Ron Hudson ha escrito:
> 1) I am not seeding the random number generator... what's a simple way?
The Applesoft random number generator uses a seed (RNDL,H, located at $4E-4F)
created by the RDKEY ($FD0C) function. Every time RDKEY is called, while the
blinking cursor is shown, the computer continuosly increases the RNDL,H
zero-page variable, which is used by the RND() function as the seed. So in
Applesoft Basic, the seed is initialized every time you go into inmediate
mode or when you execute a GET or INPUT statement.
There's another way to "seed" the random number generator, usefull when
you're debugging. You just have to call the RND() function with a *negative*
argument. That will take the argument and use it as the seed, producing a
completely predictable series of random numbers - usefull when you need a
known input set to debug a program. This also works in all Microsoft Basic
dialects I'm aware of (Applesoft, Amstrad CPC Basic, MSX Basic and
GW-Basic/QBasic/QuickBasic/Visual Basic family being the most known).
> 2) I am generating lots of numbers without key presses.. I wonder if
> I should generate a large integer then use even/odd-ness for my coin
> flip.
That would be another way of doing that. Of each call to RND() you gould get
a 16-bit integer:
N = INT(65536 * RND(1))
and then extract the 16 bits from it:
DIM BITS(15)
FOR I = 0 TO 15
BITS(I) = (N / 2 <> INT(N / 2)): N = INT(N / 2)
NEXT I
(using poor man's bitwise aritmetic, which isn't supported directly by
Applesoft O:-) ).
Greetings,
Antonio Rodr�guez (Grijan)
<ftp://grijan.cjb.net:21000/>
--
Apple2list is sponsored by <http://lowendmac.com/> and...
/ Buy books, CDs, videos, and more from Amazon.com \
/ <http://www.amazon.com/exec/obidos/redirect-home/lowendmac> \
Support Low End Mac <http://lowendmac.com/lists/support.html>
Apple2list info: <http://lowendmac.com/lists/apple2.html>
--> AOL users, remove "mailto:"
Send list messages to: <mailto:[email protected]>
To unsubscribe, email: <mailto:[EMAIL PROTECTED]>
For digest mode, email: <mailto:[EMAIL PROTECTED]>
Subscription questions: <mailto:[EMAIL PROTECTED]>
Archive: <http://www.mail-archive.com/apple2list%40mail.maclaunch.com/>
iPod Accessories for Less
at 1-800-iPOD.COM
Fast Delivery, Low Price, Good Deal
www.1800ipod.com