Re: A83: Random numbers


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

Re: A83: Random numbers




When I want random numbers, I currently use a pointer (preferably
uninitialized). Everytime I want a random number I increase the pointer,
picking up a byte from where it was pointing. This byte is 0-255, it could be
and:ed to yield 0-1, 0-3, 0-7, 0-15, 0-31, 0-63, 0-127 aswell. To get 0-8,
well... Easy solution that jumps into my mind: And the random values with 15.
Save the last random number you got. If you then get a number that's above 8,
take the previous random number, add 7, then and 15. Now, to hide this
mechanism so the user doesn't discover it, always call the random routine
about 5 times everytime you want a random number, then use only the 5th
number.

Linus

On 18-Jun-98, Alan C Johnson wrote:

>I'm making a Whack a mole game and I need to know how to get a random
>number between 1 and 9.

>-----------------------------------------------------------------------------------------------------------------------
>Mastermind--benjamin99@juno.com, www.bigfoot.com/~mastermind5
>IRC: Master_M
>ICQ: 11341114
>-Its all about the Benjamins

>_____________________________________________________________________
>You don't need to buy Internet access to use free Internet e-mail.
>Get completely free e-mail from Juno at http://www.juno.com
>Or call Juno at (800) 654-JUNO [654-5866]



References: