Re: Question about random number on AS 1.5.5
Re: Question about random number on AS 1.5.5
- Subject: Re: Question about random number on AS 1.5.5
- From: Chris Nebel <email@hidden>
- Date: Sat, 24 Feb 2001 18:58:24 -0800
- Organization: Apple Computer, Inc.
"Fernando O. Raineri" wrote:
>
Hello. I have several scripts that make use of random numbers.
>
These scripts were functioning correctly on AS 1.4.3. About
>
two weeks ago I upgraded to Mac OS 9.1 (AS 1.5.5) on a
>
Wall Street PowerBook, and noticed the following issues:
>
>
1) I turn off my PowerBook every night, and start it again
>
the next morning. All the scripts that use the random number
>
are working correctly. However, it seems that each day the random
>
numbers are started from the same seed. In other words,
>
I seem to be generating the same sequence of random numbers
>
each time I turn on the PowerBook.
>
>
2) After reading the Standard Additions manual on the subject of
>
"random number", it is my understanding that if I use
>
>
random number with seed 0
>
>
a random number based on an independent seed is generated.
>
But, at least in my case, whenever I use "with seed 0" I always
>
generate the same random number. Maybe I'm understanding the
>
manual incorrectly?
No, you're reading the manual correctly. Unfortunately, the improved
random number generator in 1.5.5 also changed the seed behavior, so the
manual is incorrect. In 1.5.5, if you use "with seed 0", it actually
resets the seed to zero. Also, it used to be that if you didn't supply
a seed at all, it would use the current time as the initial seed; now it
uses zero. I'll have to check and see whether or not this was
deliberate.
In the meantime, your best bet is to use the time as seed. In the
startup of your script, say "random number with seed time of (current
date)". Then use just "random number" (i.e., with no seed) when you
need a random number.
--Chris Nebel
AppleScript Engineering