srand((float)microtime()*1000000);
function shuffleDeck() {
global $deck;
global $targetcard;
global $decksize;
$deck = array();
for ($i = 0; $i < $decksize; $i++) {
if ($i < $targetcard) {
$deck[] = 1; // add a target card to the deck
}
else {
$deck[] = 0; // add a normal card to the deck
}
}
return;
}
function dealCard() {
global $deck;
global $decksize;
$card = array_splice($deck, array_rand($deck), 1);
return $card[0];
}
$printline = 1;
if ($numlines) {
echo "Sample trials: \n";
}
for ($g = 0; $g < $GAMES; $g++) {
if ($g >= $numlines) {
// stop printing
$printline = 0;
}
shuffleDeck();
$handCount = 0;
$foundCount = 0;
while (count($deck) > 0) {
$card = dealCard();
if ($printline) {
echo $card;
}
switch($card) {
// 1 is a target card
case 1: $foundCount++;
break;
// didn't find anything special
default: break;
} // switch
// just completed a hand
if (++$handCount == $decksize/$players) {
// do we have all the cards in one hand?
if ($foundCount == $targetcard) {
$totalWinners++;
}
$handCount = 0;
$foundCount = 0;
if ($printline) {
echo " ";
}
}
} // while
if ($printline) {
echo " \n";
}
} // for each game
?>
The total number of trials with 3 green cards in a
single hand was 0.