	title	Module from library BASE_1 : RAND8
	name	('RAND8')
	maclib	baselib.lib

; 8-bit Random Number Generator

; This is a very simple linear congruential generator.
; The formula is x[i + 1] = (5 * x[i] + 1) mod 256.
; Its only advantage is small size and simplicity.
; Due to nature of such generators only a couple of higher bits should be considered random.

; Compilation by Werner Cirsovius

; ENTRY	None

; EXIT	Accu holds pseudo-random number, period 256

	entry	Rand8

Rand8:
	ld	a,$-$		; Seed is usually 0
	ld	b,a
	add	a,a
	add	a,a
	add	a,b
	inc	a		; another possibility is ADD A,7
	ld	(Rand8+1),a
	ret

	end

