title Module from library BASE_1 : RAND16 name ('RAND16') maclib baselib.lib ; 16-bit Random Number Generator ; This generator is based on similar method but gives much better results. ; It was taken from an old ZX Spectrum game and slightly optimised. ; Compilation by Werner Cirsovius ; ENTRY None ; EXIT Reg HL holds pseudo-random number, period 65536 entry Rand16 Rand16: ld de,$-$ ; Seed is usually 0 ld a,d ld h,e ld l,253 or a sbc hl,de sbc a,0 sbc hl,de ld d,0 sbc a,d ld e,a sbc hl,de jr nc,Rand inc hl Rand: ld (Rand16+1),hl ret end