Re: Random number generator without duplicates
Re: Random number generator without duplicates
- Subject: Re: Random number generator without duplicates
- From: Daniel Robinson <email@hidden>
- Date: Thu, 19 Apr 2001 21:43:35 -0400
Scripters,
You can beat the semantics to death, but we're talking about one of two things, A
shuffled list as illustrated in my last post, or a list of randon numbers within
a range.
Below is a script that selects a random number from 1 - 10, does it a thousand
times, and logs the result.
From that result, you can see that Applescript (v 1.6) produces no appreciable
bias.
Regards,
--Dan
-------------------------------------------------------------------------
set TheList to {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
set N to the count of items in TheList
repeat 1000 times
random number N - 1 -- (I get it back on the next line)
set ThisNumber to the result + 1 -- (Don't want a zero)
set item ThisNumber of TheList to (item ThisNumber of TheList) + 1
end repeat
TheList