• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Random character String
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Random character String


  • Subject: Re: Random character String
  • From: Richard Morton <email@hidden>
  • Date: Thu, 17 Mar 2005 15:58:16 +1100

On 17 Mar 2005, at 2:16 PM, David C Andrews wrote:
On Mar 16, 2005, at 2:13 PM, Martin Orpen wrote:
on 16/3/05 7:04 pm, Michelle Steiner at email@hidden wrote:

set foo to ""
set bar to random number from 8 to 10
repeat bar times
set foo to foo & (ASCII character of (random number from 65 to 90))
end repeat
foo

This is 31 bytes better:

set x to ""
repeat (random number from 8 to 10) times
    set x to x & some item of "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
end repeat

Perhaps faster: set x to {} repeat (random number from 8 to 10) times set end of x to some item of "ABCDEFGHIJKLMNOPQRSTUVWXYZ" end repeat x as text --> "JUEQPJBH", "LFOBPXHJI", "TQRVYJPHFA"

A quicker method generally, though it would make very little difference under these circumstances. It may also be worth noting that it relies on the TIDS being set to their default value:


set text item delimiters to " * "
set x to {}
repeat (random number from 8 to 10) times
	set end of x to some item of "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
end repeat
x as text --> "R * W * W * Y * I * S * Y * Q * C * L"

To ensure that something like this will always work as expected, the TIDS should be explicitly set before coercing from list to string. Then reset back to what they were prior to the exercise if you're completely obsessive.

Cheers,

Randall Number

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: Random character String (From: Martin Orpen <email@hidden>)
 >Re: Random character String (From: David C Andrews <email@hidden>)

  • Prev by Date: Re: list to a text representation of that list (followup)
  • Next by Date: Re: getting chunks of text
  • Previous by thread: Re: Random character String
  • Next by thread: Re: Random character String
  • Index(es):
    • Date
    • Thread