; Fast random number generator using the same method
; as the CDMA used in celullar telephones

--------------------------------------------------------------------

SEED:           DW      0

--------------------------------------------------------------------
; init random seed 

INIT_SEED:
                LD      HL,(JIFFY)
                LD      A,L
                OR      1
                LD      L,A
                LD      (SEED),HL
                RET

 --------------------------------------------------------------------
; choose a random number in the set [0,127] with uniform distribution
; return: A = random value

RAND:
        PUSH    HL
        LD      HL,(SEED)
        ADD     HL,HL
        SBC     A,A
        AND     083h
        XOR     L
        LD      L,A
        LD      (SEED),HL
        AND     07Fh
        POP     HL
        RET

-- 

----------------------------------------------------------------
Ricardo Bittencourt               http://www.lsi.usp.br/~ricardo
[EMAIL PROTECTED]         "Vitrum edere possum, mihi non nocet"
------ Uniao contra o forward - crie suas proprias piadas ------

****
Problems? contact [EMAIL PROTECTED] See also http://www.faq.msxnet.org/
****

Reply via email to