Re: Random Numbers (is new: Seeding)
Re: Random Numbers (is new: Seeding)
- Subject: Re: Random Numbers (is new: Seeding)
- From: email@hidden
- Date: Sat, 30 Mar 2002 04:55:33 EST
>
I would really appreciate it if someone could point me in the
>
direction of some simple pseudo code for RNGs, (as opposed to
>
platform-optimized implementations or complex mathematical theses).
Q: looking for speed or looking for more randomness?
Q: how often do you need to pull a new random number? Since
this is often dictated in most probability games by the speed
of the user, usually less than once per second, but not always.
Related Notes from Apple's release notes on AS 1.7:
Standard Additions 1.5 through 1.6 changed the way that the
random number seed worked in the random number scripting
addition. Older versions used the system clock as the seed value
if no seed value (or a seed value of 0) was provided; Standard
Additions 1.5 and 1.6 always use a seed value of 0 in these
cases. In Standard Additions 1.7 the older behavior has been
restored. In addition, the seed value is now taken from the 60Hz
"ticks" counter rather than the system clock, because the
increased speed of new machines makes it more likely that two
consecutive random number calls may receive the same system clock
time as their seed value.
-- valid constructions of AppleScript's -- random number call
set UniqueNumber to (random number from 10001 to 99999)
[no break] as integer
set UniqueNumberName to (random number from 10001 to
[no break] 99999) as string
--=======================================
-- Quickly Generate Semi-Random Number
-- notes: only generates a new one each second
-- if you can access the ticks instead, you can
-- generate a new one each 60th of a second.
--=======================================
on OurRandNum()
set SegmentA to the time of the current date
-- Our seed value for the generation.
-- Valid range 0 - 86,399, based on
-- the number of seconds to Now
set OurSemiRandomNumber to (SegmentA mod 1039)
-- result: valid range 0 - 1038
-- Always use a prime to mod into a rand;
-- bigger prime = larger rand
-- See
http://www.rsok.com/~jrm/printprimes.html
-- to generate prime numbers in any reasonable range.
Return OurSemiRandomNumber
end OurRandNum
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.