Re: A82: Re: Random routine - human reaction times
[Prev][Next][Index][Thread]
Re: A82: Re: Random routine - human reaction times
----- Original Message -----
From: Jeremy Wazny <j.wazny@ugrad.unimelb.edu.au>
To: <assembly-82@lists.ticalc.org>
Sent: Monday, December 06, 1999 10:36 PM
Subject: Re: A82: Re: Random routine - human reaction times
>
> Okay, this is what I assumed was going on with the r register anyway. I
> haven't looked at any z80 books/documentation for ages, but I was under
> the impression that it (more or less) gets incremented by 2 for each
> machine instruction that is executed (or memory acces or whatever).
> Assuming that the processor is still in im1, the code at $0030 will keep
> getting executed even while the game waits for player input.
> In other words I assumed that r would serve as a reasonable random seed
> since the number of times it is incremented during gameplay, or before
> hand in TIOS and the shell, is practically unknowable.
>
> -Jeremy
Take for example the flow of a program with just the statement "ld a,r" to
gather a random number from.
Let us assume that we want to randomly access a routine 1 out of every 4
times, such that the following code would suffice:
main:
<blah>
ld a,r
and %11 ; the easiest way to generate a number from 1-4
(actually 0-3)
jr nz,main
<etc>
jr main
Let us assume that in an arbitrary sequence but specific number of
statements, each time that the conditional jr nz is not met, the number of
statements executed, and stored in r, ends with the last two bits being 1.
This would mean that the number generated now is not random and therefore
the program would execute as if there was no conditional statement. This is
why a random routine needs more than just register r to be considered
random.
-harper
Follow-Ups:
References: