Re: A82: Random routine
[Prev][Next][Index][Thread]
Re: A82: Random routine
I looked at the previous scheme of shuffling a deck for O(n) performance.
This is what i came up with. It's going to be a much more random stack by
getting a random number out of a seed rather than using "ld a,r"
same_code:
shuffle:
ld hl,cards ; start of 20 byte array
ld b,20
shuffle_loop:
push bc
call getrand
ld de,cards
or %1111 ; between 0 and 15
ld b,a
srl a
srl a
add a,b ; between 0 and 18
add a,e
ld e,a
ld b,(de)
ldi ; (de) = (hl) /*/ hl++ /*/ de++
ld (hl),b
pop bc
djnz shuffle_loop
getrand: ; by Jason Todd
ld a,(randseed)
ld b,a
ld a,r
add a,b
sla b
sla b
add a,b
sla b
sla b
add a,b
add a,e
inc a
rrc a
ld (randseed),a
ret
randseed: .db %10101010 ; im guessing this is better to start it off
weird than at zero
Follow-Ups:
References: