Re: A86: Random Number stuff


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

Re: A86: Random Number stuff




That is a pretty bad way to generate random numbers.  It's actually
incremented twice by some instructions (I believe all the extended ones, and
the IX/IY ones).

One good method is to multiply a 16 bit value by a constant 16 bit value,
and store the result as the seed for the next time.  Another method is to
use a table, and use a 16 bit counter to keep track of the results.  On the
86, you have the ROM as a fairly random table, so no need to generate a
unique table.

> I got this off guide.iwarp.com
> create a random number from 0 to 15
>   ld a,r
>   and %00001111 ;a is now <16
>
> you could modify it so that it is within any range you want and its a lot
> simpler than the one used it tetris however the r register is the memory
> refresh register and is incremented after every each instruction executed
by
> the processor so if it used frequently it may not be random. Also bit 7 is
> never set so it can never be greater than 127




References: