Rand ld (Rand16+1),hl
ret
</pre>
== 16-bit Random Number Generator using 'r' register ==
A pseudo random generator using the 'r' register for the first byte of the random number. It then uses this number as a seed to feed the 8-bit random number generator to generate the other byte of the random value.
'''Input:''' ''none''
'''Output:''' HL = ''a pseudo random number, period 65536''
<pre>
ld a,r
ld h,a
.rand8 ld b,a
add a,a
add a,a
add a,b
inc a
ld (rand8+1),a
ld l,a ; HL now contains a random 16-bit number
</pre>
[[Category:Programming]]