Re: A86: Random Num


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

Re: A86: Random Num





In a message dated 2/13/00 9:04:47 PM, neophile_17@hotmail.com writes:

> ld a,r      ;to find 1 of 7 rand int
> inc a       ;1 more inc a for 6, 2 for 5 etc.
> and %00000111
> dec a       ;as many decs as incs

In theory, it would work. In practice, though, since the routine is always 
called in the same place, whatever register you substitute for r will always 
have the same value.
However, if the program involves the constant use of several keys on the 
keypad then you could try something like this:

    in a, (1)   ; scans the keyboard
    rlca        ; rotates a left once
    inc a       ; once for 1-7, twice for 1-6, etc.
    xor 7       ; now a=semirandom# 1-7

You can control the keyboard input with a "out (1),%xxxxxxxx" command. Keep 
in mind that this isn't truly random in most situations. You're better off 
using Jimmy Mardell's routine from ZTetris.

    -- Jonathan Marcus