Re: A82: Random routine
[Prev][Next][Index][Thread]
Re: A82: Random routine
Actually, the value of r is used as an offset into page zero of memory, so
the randomness depends on the distribution of data there. I think that's
where the zero you're talking about came from.
I think that probably even the simplest scheme for random number
generation would suffice in this case; who's going to be able to mentally
pick the next combination of cards from their current state? :)
-Jeremy
On Sun, 5 Dec 1999, Harper Maddox wrote:
>
> 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: