[A83] Re: shuffle code help please
[Prev][Next][Index][Thread]
[A83] Re: shuffle code help please
Could you send us the output? for a basic bingo card maker, I made a random
number, checked if it was the same, and placed it. Perhaps use a form of
stack where it takes a number from a list and compacts the remaining list
with a djnz loop with b = 52-card number, I think, along with an inc to
increase number and pointer.
Too early for my brain,
Jimmy Pardey
>this isnt the worlds most elegant code but it works, somewhat. I am trying
>to
>shuffle 52 cards ranging from 0..51. the method i am trying is takeing 2
>random slots and swapping them, then repeating the process 255 times. after
>i
>run this code and check it i am getting repeates in the sequence.
>
>shuffle:
> ;new idea take two random slots and swap them
> ld b,255
>again:
> push bc ;save the main loop var
> ld b,52
> call irandom ;get random number 0-51
> ld (slot1),a
> ld b,52
> call irandom ;another random number 0-51
> ld (slot2),a
> ld hl,carddeck ;start to put slot1 into slot2
> ld a,(slot2)
> ld b,0
> ld c,a
> add hl,bc ;get address of deck+slot number
> ld a,(slot1)
> ld (hl),a
> ld hl,carddeck ;start to put slot2 into slot1
> ld a,(slot1)
> ld b,0
> ld c,a
> add hl,bc
> ld a,(slot2)
> ld (hl),a
> pop bc
> djnz again
> ret
>
>carddeck:
> .db 0,1,2,3,4,5,6,7,8,9,10
> .db 11,12,13,14,15,16,17,18,19,20
> .db 21,22,23,24,25,26,27,28,29,30
> .db 31,32,33,34,35,36,37,38,39,40
> .db 41,42,43,44,45,46,47,48,49,50
> .db 51
>
>slot1:
> .db 0
>slot2:
> .db 0
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com