Random sort demonstration

Dr. Hawkins dochawk at gmail.com
Thu May 23 10:36:52 EDT 2013


On Thu, May 23, 2013 at 6:51 AM, Richard Gaskin
<ambassador at fourthworld.com> wrote:
> Wouldn't that put the probability of sorting bottom-to-top unusually high,
> since there the odds are 4294967292-to-1 that the sort integer will exceed
> the number of lines in the list?

If I'm reading the prior posts right, that won't be a problem, because
all of the lines will have such a number.

Whereas for a small list, there could indeed be a problem:  if numbers
from 1 to three are being generated, there is only a 1/3 chance that
all of the numbers from 1 to 3 are generated (1*2/3*1/3).
There is also a 1/3 chance that the same number is generated three
times (3*(1/3*1/3)).

In such cases, the order of the affected lines (the ones with the
multiply drawn number) would not change (e.g., if both have "2", they
will both be left where they are).  Put another way, 2/3 of the time,
one or more lines will not be subject to sort.

That said, sorting three lines by random(3) is not going to give
random results.  A number that is large compared to the lines sorted
is needed
-- 
Dr. Richard E. Hawkins, Esq.
(702) 508-8462




More information about the use-livecode mailing list