Subject: | |
From: | |
Reply To: | |
Date: | Mon, 14 Apr 2008 12:28:19 +0100 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
"Mark J. Reed" wrote on Sun, 13 Apr 2008 18:06:11 -0400:
>My code is a complete solution. No need to change it, other than to
>correct my syntax errors. Here's the corrected version:
>
>on shuffle(aList)
> set listSize to count aList
> repeat with i from listSize to 2 by -1
> set j to random number from 1 to i
> if j is not i then
> tell aList to set {item i, item j} to {item j, item i}
> end if
> end repeat
>end shuffle
Hi, Mark.
My own attempt at a list randomiser looks like this:
on shuffle(aList)
script o
property l : aList
end script
set lengthMinus1 to (count aList) - 1
repeat with i from 1 to lengthMinus1 + 1
set j to (random number lengthMinus1) + 1
set v to item i of o's l
set item i of o's l to item j of o's l
set item j of o's l to v
end repeat
end shuffle
Apart from the fact that it uses AppleScript performance logic
(referenced list variable, different random number syntax, not bothering
to see if j = i, not setting-by-list), are there any randomness
implications in the fact that my item i can be exchanged with any item in
the list, whereas yours is only exchanged with items that come in front of it?
NG
|
|
|