Two Plus Two Older Archives  

Go Back   Two Plus Two Older Archives > General Gambling > Computer Technical Help
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 10-24-2005, 02:48 PM
Mr. Curious Mr. Curious is offline
Senior Member
 
Join Date: Jul 2005
Location: Only a stranger to people I haven\'t met
Posts: 251
Default Card Shuffling Algorythm

Howdy!

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

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

Thanks!
Reply With Quote
  #2  
Old 10-24-2005, 03:30 PM
StevieG StevieG is offline
Senior Member
 
Join Date: Jan 2003
Location: Baltimore, MD, USA
Posts: 157
Default 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 />
Reply With Quote
  #3  
Old 10-24-2005, 08:16 PM
Mr. Curious Mr. Curious is offline
Senior Member
 
Join Date: Jul 2005
Location: Only a stranger to people I haven\'t met
Posts: 251
Default Re: Card Shuffling Algorythm

That code would randomize a deck once, but does it actually emulate a shuffle?
Reply With Quote
  #4  
Old 10-24-2005, 08:26 PM
StevieG StevieG is offline
Senior Member
 
Join Date: Jan 2003
Location: Baltimore, MD, USA
Posts: 157
Default Re: Card Shuffling Algorythm

Are you actually looking for a stochastic model of physical shuffling techniques like riffling, washing, and boxing?
Reply With Quote
  #5  
Old 10-25-2005, 11:37 AM
Mr. Curious Mr. Curious is offline
Senior Member
 
Join Date: Jul 2005
Location: Only a stranger to people I haven\'t met
Posts: 251
Default 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?
Reply With Quote
  #6  
Old 10-25-2005, 11:51 AM
StevieG StevieG is offline
Senior Member
 
Join Date: Jan 2003
Location: Baltimore, MD, USA
Posts: 157
Default Re: Card Shuffling Algorythm

That shuffle algorithm ought to do the trick.
Reply With Quote
  #7  
Old 10-25-2005, 12:02 PM
Mr. Curious Mr. Curious is offline
Senior Member
 
Join Date: Jul 2005
Location: Only a stranger to people I haven\'t met
Posts: 251
Default 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.
Reply With Quote
  #8  
Old 10-25-2005, 12:26 PM
kenberman kenberman is offline
Junior Member
 
Join Date: Dec 2003
Posts: 1
Default 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
Reply With Quote
  #9  
Old 10-25-2005, 12:32 PM
StevieG StevieG is offline
Senior Member
 
Join Date: Jan 2003
Location: Baltimore, MD, USA
Posts: 157
Default 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.
Reply With Quote
  #10  
Old 10-25-2005, 02:53 PM
cgwahl cgwahl is offline
Member
 
Join Date: Nov 2004
Posts: 51
Default 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...
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:30 PM.


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