#1
|
|||
|
|||
Card Shuffling Algorythm
Howdy!
Does anyone have a shuffling algorythm in C/C++ code? Searching for "Shuffling" didn't turn up anything helpful. Thanks! |
#2
|
|||
|
|||
Re: Card Shuffling Algorythm
From the Perl FAQ on data manipulation, here is the Fisher Yates shuffle, which will shuffle an array in linear time.
This is in Perl, and its randomness is dependent on the rand function. <font class="small">Code:</font><hr /><pre> sub fisher_yates_shuffle { my $deck = shift; # $deck is a reference to an array my $i = @$deck; while ($i--) { my $j = int rand ($i+1); @$deck[$i,$j] = @$deck[$j,$i]; } } </pre><hr /> |
#3
|
|||
|
|||
Re: Card Shuffling Algorythm
That code would randomize a deck once, but does it actually emulate a shuffle?
|
#4
|
|||
|
|||
Re: Card Shuffling Algorythm
Are you actually looking for a stochastic model of physical shuffling techniques like riffling, washing, and boxing?
|
#5
|
|||
|
|||
Re: Card Shuffling Algorythm
No, I don't think so. What I am looking to do is write a blackjack program that I can use to teach myself basic strategy and then card counting. In order to do it right, I need to create card shuffling algorythm that can completely randomize a deck.
Perhaps there is a better way to represent a deck than to use an array which would then provide for an easy way to shuffle? |
#6
|
|||
|
|||
Re: Card Shuffling Algorythm
That shuffle algorithm ought to do the trick.
|
#7
|
|||
|
|||
Re: Card Shuffling Algorythm
Thanks.
btw - I don't know if Perl allows for the API GetTickCount(), but if so, you can use it as the random seed to ensure that each run is based off of a different random number. |
#8
|
|||
|
|||
Re: Card Shuffling Algorythm
[ QUOTE ]
No, I don't think so. What I am looking to do is write a blackjack program that I can use to teach myself basic strategy and then card counting. In order to do it right, I need to create card shuffling algorythm that can completely randomize a deck. Perhaps there is a better way to represent a deck than to use an array which would then provide for an easy way to shuffle? [/ QUOTE ] play for free at any online casino. read about UB's shuffler to know why it is so difficult to do w/ code alone |
#9
|
|||
|
|||
Re: Card Shuffling Algorythm
GetTickCount will seed, but see this bit on identical Minesweeper boards.
If you really need to make a good PRNG, it's probably worth looing into some sort of entropy pool for seeding. I think for your BJ practice app, GetTickCount() would be fine. |
#10
|
|||
|
|||
Re: Card Shuffling Algorythm
[ QUOTE ]
No, I don't think so. What I am looking to do is write a blackjack program that I can use to teach myself basic strategy and then card counting. In order to do it right, I need to create card shuffling algorythm that can completely randomize a deck. Perhaps there is a better way to represent a deck than to use an array which would then provide for an easy way to shuffle? [/ QUOTE ] Just download this BJ simulator. http://www.s-a-g-e.com/dwnlds.html Stanford Wong said it does a pretty good job on his website... |
|
|