Re: A82: random numbers
[Prev][Next][Index][Thread]
Re: A82: random numbers
To get a random number into the a register:
ld a, r
srl a
and %00001111 ; This number must be a power of two minus one: {1,3,7,15,31,63,127}. And 7 will return a number between 0 and 7. And 10 will come out really badly.
To display what is in the a register: (To display a 16 bit number, just load it into hl)
ld l, a
ld h, 0
ROM_CALL(D_HL_DECI)
The Weilers wrote:
> I tried to write my own random number routine, which looked like this:
>
> ld a,r
> srl a
> and 10
> ROM_CALL(TR_CHARPUT)
>
> like it says in Zshell School.
>
> This would only give me four randomized things, and they were a filled in box, an empty box, some sort of math symbol, and the checkerboard box.
>
> I then tried to use rand.asm, but it locked up my calculator. I first tried the CALL_ thing, like rand.asm said to use, and the compiler didn't even let me use it. Then I tried "call" and "jp", which locked up my calculator.
>
> How do I get a random number ?!?!?!?!?!?!?!?!?!
References: