2 ; Randum number generator
4 ; Written and donated by Sidney Cadot - sidney@ch.twi.tudelft.nl
6 ; May be distributed with the cc65 runtime using the same license.
10 ; void srand (unsigned seed);
13 ; Multiplier must be 1 (mod 4)
14 ; Added value must be 1 (mod 2)
15 ; This guarantees max. period (2**32)
16 ; Bits 8-22 are returned (positive 2-byte int)
17 ; where 0 is LSB, 31 is MSB.
18 ; This is better as lower bits exhibit easily
19 ; detectable patterns.
31 lda rand+0 ; SEED *= $01010101
39 lda rand+0 ; SEED += $31415927
49 and #$7f ; Suppress sign bit (make it positive)
54 pla ; return bit 8-22 in (X,A)
57 _srand: sta rand+0 ; Store the seed
60 sta rand+2 ; Set MSW to zero