Re: processing time & stack overflow
Re: processing time & stack overflow
- Subject: Re: processing time & stack overflow
- From: Arthur J Knapp <email@hidden>
- Date: Tue, 28 Aug 2001 11:05:04 -0400
>
Date: Tue, 28 Aug 2001 11:20:31 +1000
>
Subject: Re: processing time & stack overflow
>
From: Timothy Bates <email@hidden>
>
to randomize(TheList)
>
repeat with i from length of TheList to 1 by -1
>
set current_item to some item of TheList's items 1 thru i
>
tell TheList -- exchange item current_item with item i
>
set temp to contents of item i
>
set item i to contents of current_item
>
set current_item to temp
>
end tell
>
end repeat
>
return TheList
>
end randomize
I'm afraid that I haven't been following this thread, so I'm not sure
what is needed here, but I noticed that the above handler does not
randomize in the sense that each item is preserved and occurs in a
new place:
set myList to {"a", "b", "c", "d"}
randomize(myList)
myList --> {"a", "a", "b", "b"}
randomize(myList)
myList --> {"a", "a", "a", "a"}
randomize(myList)
myList --> {"a", "a", "c", "c"}
I suspect that the above are not the desired results.
This is a modification of a script that I posted a few months ago, it
uses only one osax call:
on NewOrder(lst)
set {s1, s2, len} to ,
{random number from 1 to 100000, 31415, lst's length}
repeat with i from 1 to len
set {j, s1} to {(s1 mod len) + 1, (s1 * s2) mod len}
set {lst's item i, lst's item j} to ,
{lst's item j, lst's item i}
end repeat
end NewOrder
set lst to {"a", "b", "c", "d"}
NewOrder(lst)
lst --> {"b", "c", "d", "a"}
NewOrder(lst)
lst --> {"c", "a", "b", "d"}
NewOrder(lst)
lst --> {"c", "b", "a", "d"}
The problem with using "some item" is that you can't keep track
of the index location from which the item came from. "some item"
only returns the value of that item.
P.S. My handler still needs to be more thoroughly tested...
Arthur J. Knapp
http://www.stellarvisions.com
mailto:email@hidden
Hey, check out:
http://www.LateNightSW.com