# randomly order a list

Dar Scott dsc at swcp.com
Thu May 23 15:41:57 EDT 2013

```I agree, Geoff!  Your theory and measurements are consistent with mine for 3.

An important part of Geoff's test is this:
>      put originalList into newList

Dar

On May 23, 2013, at 1:30 PM, Geoff Canyon wrote:

> 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. ;-)
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

```