Mime-Version: |
1.0 (Apple Message framework v753) |
Sender: |
|
Date: |
Sun, 13 Apr 2008 14:15:53 -0600 |
Reply-To: |
|
Subject: |
|
Content-Transfer-Encoding: |
7bit |
In-Reply-To: |
|
Content-Type: |
text/plain; charset=US-ASCII; delsp=yes; format=flowed |
From: |
|
Parts/Attachments: |
|
|
On Apr 13, 2008, at 1:26 PM, Chuck Pelto wrote:
>
> On Apr 13, 2008, at 1:12 PM, Chuck Pelto wrote:
>
>>
>> On Apr 13, 2008, at 1:01 PM, Mark J. Reed wrote:
>>
>>> On Sun, Apr 13, 2008 at 2:51 PM, Chuck Pelto <[log in to unmask]>
>>> wrote:
>>>> Does anyone have a good suggestion on how to shuffle the
>>>> contents of a list?
>>>
>>> Fisher-Yates is a good algorithm. What language?
>>
>> Working with AppleScript; ScriptDebugger.
>>
>> Where can I find the Fisher-Yates?
>
> Found it. Looks simple enough.
Here's what I've done.....
on ShuffleList(thisList)
set iCount to (count of items in thisList) -- get number of items in
the list
set itCount to iCount
repeat until itCount < 2
set randNumb to (random number from 1 to itCount)
if randNumb is not equal to itCount then
set i1 to item itCount of thisList
set i2 to item randNumb of thisList
set item itCount of thisList to i2
set item randNumb of thisList to i1
end if
set itCount to itCount - 1
end repeat
return thisList
end ShuffleList
It's not particularly elegant, but it works.
|
|
|