randomly order a list
Geoff Canyon
gcanyon at gmail.com
Thu May 23 15:30:57 EDT 2013
There is, indeed much confusion here. I, of course, am correct ;-)
I simplified the problem to a list of two items:
1,2
That way the sort command has exactly two outcomes. It either reverses the
list, or it doesn't. The two outcomes should happen roughly 50% of the
time. This script demonstrates that sorting by a large random number works,
and sorting by a random number up to the number of items (2) does not.
on mouseUp
put "1,2" into originalList
repeat 10000
put originalList into newList
sort items of newList by random(2)
if newList is originalList then add 1 to sameCount1
end repeat
repeat 10000
put originalList into newList
sort items of newList by random(999999999)
if newList is originalList then add 1 to sameCount2
end repeat
put "Sorting by random(2) kept the same order" && sameCount1 && "out of
10000 times." & cr & \
"Sorting by random(999999999) kept the same order" && sameCount2
&& "out of 10000 times."
end mouseUp
For anyone interested in the math, as you would expect, the random numbers
for the sort come out 2,1 roughly 1/4 of the time, so the result is that
the list is in the same order roughly 75% of the time when using random(2).
Here's one result I got:
Sorting by random(2) kept the same order 7514 out of 10000 times.
Sorting by random(999999999) kept the same order 5014 out of 10000 times.
If anyone disagrees, come at me, bro. ;-)
More information about the use-livecode
mailing list