News:

Function Finder  Find all the functions within source code files

Main Menu

Shuffle Deck Of cards

Started by kevin, August 02, 2010, 09:40:19 AM

Previous topic - Next topic

kevin

 Shuffle Deck Of cards



PlayBASIC Code: [Select]
   ; Dim array to hold the Deck
Dim Deck(52)

; seed the card array from 1 to 52
For lp=1 to 52
Deck(lp)=lp
next

; Shuffle the card array
Shuffle(2)

; Display cards
For lp=1 to 52
Card=Deck(lp)
row$+=str$(Card)
count++
if count=4
print row$
Count=0
Row$=""
else
Row$+=","
endif
next

;
Sync
WaitKEY



Function Shuffle(Passes)
for pass=1 to passes
For lp=1 to 52
pos=rndrange(1,52)

Temp1=Deck(lp)
Temp2=Deck(pos)

Deck(pos)=Temp1
Deck(lp)=Temp2

next
next
EndFunction