On Sat, 26 Aug 2000, you wrote:

> > In its current form, it produces numbers in the range 0..27, but you can
> > easily change that. You have to know that the middle bits of the seed are
> > the most "random", so use those for the result.
>
> Thanks Maarten. And yes, I knew that the middle bits of R were most
> 'random' but it just wasn't random enough for me.

I meant the middle bits of RandomSeed in the source...

The thing about R is that it's not random at all. It is just a very fast 
counter. But because it's so fast and only 8 bits wide, it overflows very 
often and therefore seems random. R is very useful to create a seed for a 
random generator, but R not useful when you read it repeatedly.

Code like this:
        ld      a,r
        ld      b,a
        ld      a,r
        sub     b
will produce a constant number. I'm not sure if it's 100% constant, but it 
will at least be around the same value. You can increase the value by putting 
some NOPs between the two "ld a,r" instructions.

As far as I know, Z380 doesn't have an R register that actually counts (it's 
always zero). So if you want your code to run on Z380 and some other 
Z80-compatibles, don't use R as your only source of "randomness".

Bye,
                Maarten


****
Problems? contact [EMAIL PROTECTED] See also http://www.faq.msxnet.org/
****

Reply via email to