In AppleSoft, RND
with a negative number performs a seed on the generator with that number. So, as I understand it X=RND(-1)
is the equivalent of RANDOMIZE 1:X=RND(1)
:
If aexpr is positive, returns a random number from 0 to 0.999.... If aexpr is zero, repeats the last result. If aexpr is negative, reseeds the generator.
That middle bit is a surprise to me, and seems quite odd from a portability perspective considering how many programs used 0 as a dummy value. I assume Apple users simply learned to change this to some other value, like 1.
The C64 quick reference states:
RND(exprnm)—Returns a random number between and 1 if exprnm is positive. If exprnm is zero, returns, a "randomized" random number. If exprnm is negative, returns a preset random number.
This is similar to the AppleSoft version (as one would expect) except for the zero case, and that bit about the "'randomized' random number" could mean one of several things. So I looked in the C64 user guide page 126 and get this:
RND(X) returns a random number in the range 0-1. The first random number should be generated by the formula RND(-TI) to start things off differently every time. After this, X should be a 1 or any positive number. If X is zero, the result will be the same random number as the last one.
That seems quite at odds with the version in the quick reference. So then I checked the C64 wiki page on RND:
- By using RND(<positive number>) gives a different random number each time from a predetermined sequence (the sequence number is stored internally).
- […] typical use is to call RND(<negative number>) once and then repeatedly call RND(<positive number>).
So, my questions for those more deeply familiar with the Commodore systems:
is the issue with
RND(0)
simply because the C64, specifically, does not automatically start the appropriate timer at startup? The wiki suggests that other CBM platforms do, and that the statement in the Quick Reference is thus accurate for those machines (and likely just copied).are all positive parameters otherwise equivalent? Will
RND(10)
andRND(20)
perform the same internal operation? The wiki can be read to suggest these are different sequences, but I find that difficult to believe.
P.RND(1000):P.RND(0)
, the second number will be approximately 1/1000th of the first.