[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Where does the Applesoft RND() function get its data?



I can't speak about the Applesoft RND() specifically though I can look
it up when I get home if that's what you really need.

On an Apple IIgs I tend to seed my Pseudo Random Number Generator
(PRNG) using the current value of the one of the Mega II Video Counter
values located at $C02E and $C02F.

Then (this is what I used for my fire demo last week) I found this
brilliant piece of code for 'randomizing' through all possible
values.  Very awesome for the size involved.  (The code below assumes
RND is a byte where we'll store our number)

GetRnd
   lda RND
   beq :doEor
   asl
   bcc :noEor
:doEor eor #$1d
:noEor sta RND
   rts


That's basically what my implementation in Merlin looks like but go
see David Holz's page for a description and on how to increase the
number of possible values before repeating and expanding to 16bit (or
more) values.

David Holz's Article where I got this awesome bit of code:
A tiny, fast, 8-bit pseudo-random number generator in 6502 assembly
http://codebase64.net/doku.php?id=base:small_fast_8-bit_prng

You can also see it in my code from this demo (included on the
downloadable prodos image) though in my case I immediately remap it to
one of two values to seed my fire.
http://www.dagenbrock.com/blog/?q=node/23