[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Where does the Applesoft RND() function get its data?
vladitx <vladitx@nucleusys.com> wrote:
> On Feb 25, 10:48 am, "Jayson Smith"
> <ihatespamratguynospample...@insightbb.spamsucks.com> wrote:
> > I'm just wondering where the Applesoft RND() function gets its numbers. Is
> > there a spot in memory that contains random values, or a machine language
> > routine, or what?
>
> Just by memory - I think the subroutine that produces pseudo-random
> numbers uses entropy from a counter incremented by the KEYIN loop.
Nope. There is an entropy generator ($4E and $4F are incremented as a
16-bit number while waiting for a keypress) but there is nothing to
connect that automatically to the Applesoft RND() function.
By itself, RND() is a standard pseudo-random number generator which uses
a formula to calculate the next number in a sequence, which will
eventually wrap around and repeat the same pattern. I don't think I ever
knew the specific algorithm used by Applesoft.
The "wait for keypress" method is a good way to _seed_ the random number
generator. My vague recollection is that you seed RND() by passing it a
negative number, which you could construct from values PEEKed from
$4E/$4F.
--
David Empson
dempson@actrix.gen.nz