MACSCRPT Archives

April 2008

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Chuck Pelto <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Sun, 13 Apr 2008 14:15:53 -0600
Content-Type:
text/plain
Parts/Attachments:
text/plain (55 lines)
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.

ATOM RSS1 RSS2