Re: Random Numbers fasters than the osax
Re: Random Numbers fasters than the osax
- Subject: Re: Random Numbers fasters than the osax
- From: Christopher Nebel <email@hidden>
- Date: Thu, 28 Mar 2002 10:32:17 -0800
On Wednesday, March 27, 2002, at 11:07 AM, Michael Sullivan wrote:
the only good changing
number I can think to seed it with is ticks, which is another osax --
and to get real random numbers I'd need to reseed every time, no?
That depends on what you mean by a "real" random number. Any sort of
purely numerical technique only gives you pseudo-random numbers, but for
your application you may not care.
Seeding with the ticks isn't much better, since the seed values are
fairly predictable. You don't need the "ticks" addition to do this --
specifying a seed of zero will re-seed from the clock. There are two
caveats, however: one, this behavior is broken in AppleScript 1.5.5 and
1.6, so "random number with seed 0" will always return the same answer.
Second, the clock only changes every 1/60th of a second, so if you call
"random number with seed 0" fast enough, you'll get the same answer
several times in a row.
To get *really* random data, you need some real-world source of
randomness. These are certainly available -- see
http://lavarand.sgi.com for one example -- but they're likely to be
slower than calling "random number". If you're using Mac OS X, you
might find it interesting to fool around with /dev/{s,u}random.
--Chris Nebel
AppleScript Engineering
_______________________________________________
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.