Location: PHPKode > scripts > PHP Poker Engine > php-poker-engine/pokerDeck2_readme.txt
PokerDeck2.php Release Note


Overview:
PokerDeck2.php was created to acknwoledge the limitations of the shuffle() method previously used
to shuffle the cards.  That method's "randomness" is somewhat lackluster and can ceate multiple versions
of the same exact deck when you run it over and over again a few hundred thousand times (thanks to 
Jerome Vallet of France for pointing that out and suggesting the use of the mt_rand() function instead.

This change to the mixThem() method is the only change to this release of the deck class now renamed pokerDeck2.php
JUST BE SURE TO UPDATE YOUR REFERENCES TO THE INCLUDE FILE PATH TO REFLECT THE NEW FILE NAME - SEE TEST CODE BELOW FOR EXAMPLE.

The mixThem method now looks like this:

public function mixThem()
	{//start MixThem bracket
		//these are the cards that will be shuffled and put into the deck
		$startingDeck=array("2H","3H","4H","5H","6H","7H","8H","9H","10H","JH","QH","KH","AH","2C","3C","4C","5C","6C","7C","8C","9C","10C","JC","QC","KC","AC","2D","3D","4D","5D","6D","7D","8D","9D","10D","JD","QD","KD","AD","2S","3S","4S","5S","6S","7S","8S","9S","10S","JS","QS","KS","AS");
		//this outer loop says that while the deck has < 52 items in it do the following...
		while ((count($this->deck))<52) 
		{//start outer while loop
				//a piece of data here is a random value/card from $startingDeck
				$data = $startingDeck{mt_rand(0,51)};
				//to ensure that you don't put the same value in twice we have the inner loop
				while (!in_array($data, $this->deck)){//start inner while loop
				array_push($this->deck, $data);
				}//end inner while loop
		}//end out while loop
	}//end mixThem

PLEASE NOTE: THE INITIAL DATA IN THE DECK ARRAY (i.e the sequential non-shuffled cards 2H, 3H, etc) HAS BEEN
REMOVED.  THAT DATA IS NOW POPULATED WHEN YOU CALL THE MIXTHEM() METHOD. PLEASE BE AWARE OF THIS IF YOU CREATED 
YOUR OWN SHUFFLE METHOD- IN SUCH CASE, DON'T USE THIS DECK OR IT MAY NOT WORK.

Otherwise, the use is the same as the other deck, please refer to that documentation.  Here is some quick code to
test the new deck if you want to see the file in action:

<?php
//to test new deck random mixThem function
	include("pokerDeck2.php");
	$aDeck = new Deck();
	$aDeck->mixThem();
	print"<p>This is the shuffled deck: </p>";
	print_r($aDeck);
	print"<p>\n</p>";
?>
Return current item: PHP Poker Engine