Random generators

Random Number Generator (8-bit)
Generates a psuedo random number between 00h and FFh; the random number is loaded into A. The seed for the random number is held at location RandSeed.

ld hl,(RandSeed) ld a,r ld d,a ld e,(hl) add hl,de add a,l xor h      ld (RandSeed),hl

Random Number Generator (16-bit)
Generates a psuedo random number between 0000h and FFFFh; the random number is loaded into HL. The seed for the random number is held at location RandSeed.

ld de,(RandSeed) ld a,d ld h,e ld l,$FD or a      sbc hl,de sbc hl,de ld d,0 sbc a,d ld e,a sbc hl,de jr nc,Rand inc hl Rand  ld (RandSeed),hl