Two Plus Two Older Archives

Two Plus Two Older Archives (http://archives2.twoplustwo.com/index.php)
-   Computer Technical Help (http://archives2.twoplustwo.com/forumdisplay.php?f=46)
-   -   Card Shuffling Algorythm (http://archives2.twoplustwo.com/showthread.php?t=364402)

Mr. Curious 10-24-2005 02:48 PM

Card Shuffling Algorythm
 
Howdy!

Does anyone have a shuffling algorythm in C/C++ code?

Searching for "Shuffling" didn't turn up anything helpful.

Thanks!

StevieG 10-24-2005 03:30 PM

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 />

Mr. Curious 10-24-2005 08:16 PM

Re: Card Shuffling Algorythm
 
That code would randomize a deck once, but does it actually emulate a shuffle?

StevieG 10-24-2005 08:26 PM

Re: Card Shuffling Algorythm
 
Are you actually looking for a stochastic model of physical shuffling techniques like riffling, washing, and boxing?

Mr. Curious 10-25-2005 11:37 AM

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?

StevieG 10-25-2005 11:51 AM

Re: Card Shuffling Algorythm
 
That shuffle algorithm ought to do the trick.

Mr. Curious 10-25-2005 12:02 PM

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.

kenberman 10-25-2005 12:26 PM

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

StevieG 10-25-2005 12:32 PM

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.

cgwahl 10-25-2005 02:53 PM

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...


All times are GMT -4. The time now is 01:27 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.