; ;################################### ;# DETERMINISTIC RANDOM GENERATORS # ;# AS65 source. Public domain # ;# (1997) by B.W.van Schooten # ;################################### ;The random generators: ;====================== ; RND (rnd/randomize) ; ; Reasonably random. Uses a 32-bit seed. ; ; ; QUICKRND (quickrnd/quickrandomize) ; ; Shift-counter. Limited but fast & short. Uses a 16-bit seed. Has a period ; of 65535(the maximum). The initial seed must not be 0. ; ; rndseed equ $340;4b quickrndseed equ $344;2b org $fff db 1,16 ;StartAdr=$1001 db 11,16,204,7,158,'4109',0,0,0 ;BASIC program SYS$100D ;The following routine demonstrates the use of both random generators. ;The top half of the screen shows RND, the bottom half shows QUICKRND. entry: jsr randomize jsr quickrandomize lda #8 sta $900f loop: jsr rnd tax lda #128+32 inc $1e00,x jsr quickrnd tax lda #128+32 inc $1f00,x jmp loop ;----------------------------------- RND ----------------------------------- randomize: lda $9124 sta rndseed lda $9125 sta rndseed+1 lda $9004 sta rndseed+2 lda $9003 sta rndseed+3 rts ;u:rndseed ;O:A=RND number rnd: sec ;Make sure it's deterministic lda #$7a adc rndseed sta rndseed rol a rol a adc #$69 adc rndseed+1 sta rndseed+1 adc #$a3 rol a rol a rol a rol a adc #$e1 eor rndseed+2 sta rndseed+2 rol a rol a rol a rol a rol a adc #$57 adc rndseed+3 sta rndseed+3 rts ;------------------------------- QUICKRND ---------------------------------- ;u:P A ;O: quickrndseed quickrandomize: lda $9124 sta quickrndseed ora #1 ;Make sure seed is always != 0 sta quickrndseed+1 rts ;u:P quickrndseed ;O:A=RND number. quickrnd: lda quickrndseed+1 asl quickrndseed rol quickrndseed+1 adc #0 and #1 ;XOR with bit that was shifted out ora quickrndseed sta quickrndseed rts