Re: A86: Random Number stuff
[Prev][Next][Index][Thread]
Re: A86: Random Number stuff
In a message dated 1/9/00 7:39:17 PM Mountain Standard Time, MikeT843@aol.com
writes:
> 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
This doesn't really work as well as Jimmy's randomization...the randomization
isn't good at all really, unless you throw in some other stuff to randomize
the R register. For example, to use this masking method to get a number
between 0 and 9, you can't simply do:
ld a,r
and 9
...cause 9 wouldn't work as a mask in this case. You *could* do something
like:
Loop:
ld a,r
and $0F
cp 9+1
jr nc,Loop ;jump if resulting number isn't between 0 and 9
However, if, after the masking instruction (the < and $0F>), the result is
10, the next randomized number will always be some other number that will
always be the same (I think if it relooped and it was 10, it would be
14...which would cause another reloop to 2). So some numbers are almost
always guarenteed to come up twice or three times as much as other numbers
(which means bad randomization).
Of course, this method of masking off bits of the R register works great if
you need a random number between 0 and 15, for example...but for other
ranges, it doesn't work too well.
JayEll