Re: A83: Random numbers


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

Re: A83: Random numbers




You're probably doing some sort of wait-for-key loop somewhere. Modify it to
something like this:

keyloop: call  _getkey
         ; Insert some jump-away-if-key-pressed stuff here
         ld    hl,random
         ld    a,(hl)
         inc   a
         ld    (hl),a
         cp    7
         jr    nz,keyloop
         ld    (hl),0
         jr    keyloop

Total size: 17 bytes.

The random number will depend on for how long time the user didn't press any
key.

Linus

On 29-Jun-98, Michael Bryan Cook wrote:

>O.K. I've got a question for you guys. Maybe you can solve this Olle. How 
>would you go about generating a random number (the fastest way possible) 
>between (and including) 0 and 6. The smaller the better. Also, what range 
>does the _RANDOM call return?

>Michael Bryan Cook
>------------------------------
>E-Mail - MBCook@MBCook.com
>------------------------------
>Web Page - http://www.MBCook.com
>Amazed Guy Award Page - http://www.MBCook.com/amazed.html
>MIDI Page - http://www.MBCook.com/midi.html
>NetSmart Page - http://www.MBCook.com/netsmart.html
>Parodies Page - http://www.MBCook.com/parodies.html
>Rush Sounds Page - http://www.MBCook.com/rush.html
>TI Page - http://www.MBCook.com/ti.html
>------------------------------
>I pledge allegiance to the compatibles of IBM, and everything that goes 
>with them. And for the companies under which it stands, one industry, under 
>Bill, with games and perhapsles for all!




Follow-Ups: References: