<?
header("Content-type: text/plain");
// Establishes the pool of cards$cardPool=array('Spade', 'Heart', 'Diamond', 'Club');
// Sorts them alphabeticallysort($cardPool);
// Displays cardpoolprint_r($cardPool);
// We want to count each try to get 10 hearts and first we set the counter to zero$tryCounter=0;
do {
// Add 1 to the number of tries we've done$tryCounter++;
// Establish and reset the "hand"$hand=array();
// Tell our program to do something 10 timesfor($run=1; $run<=10; $run++) {
// Randomly pick one card from the cardpool $pickedCard=$cardPool[array_rand($cardPool)];
// Accumulate the number of "picked card" in the hand by one$hand[$pickedCard]++;
}
//printf("Hearts after run %u: %u\n", $run, $cardSet['Heart']);// We have this to avoid making the program run infinitely if we screw up the codeif( $tryCounter>10000000 ) {
break;
}
// At end of try, see if we have 10 Hearts in hand, if so, stop loop
} while( $hand['Heart'] <10 );
// Display a report on how many runs it took to gain a hand of only heartsprintf("Result reached after %u runs\n", $tryCounter);
// Print the full handprint_r($hand);