25000) $trials = 10; if(!is_int(intval($trials))) { echo "problem: $trials"; exit; } ?>

ESP Simulation

If you had 10 people write their name on a card and seal each in identical envelopes, mixed up the envelopes, then gave them to your friend to return to each person. How many people would he have to match correctly to convince you that he had ESP? This simulation will help you make up your mind. Choose how many trials you'd like to run, then click "Run Simulation". The resulting table will highlight any matches that were made. It will also keep a running tally of the average number of matches per trial and the frequency of perfect matches. It's interesting to check and see what the maximum number of matches was in any given trial, but that can be tedious with thousands of trials. For that reason, below the table it will display that maximum.

Number of trials: (maximum 25000)

Please wait . . .
"; $output .= "TrialValuesMatchesAvg. Matches
per trialFreq. of perfect
match\n"; for($i=1;$i<=$trials;$i++) { $output .= "$i"; foreach(random_loop(10, 0, 9) as $num => $value) { if($num == $value) { $count += 1; $output .= ""; } $output .= " $value "; if($num == $value) $output .= ""; } //end foreach if($count==10) $perfects += 1; $output .= "$count"; $total_count += $count; $output .= "$total_count/$i = "; $output .= round($total_count/$i,4); $output .= ""; $output .= "$perfects/$i = "; $output .= $perfects/$i; $output .= ""; $output .= "\n"; if($count>$max_count) $max_count = $count; $count = 0; } //end for $output .= ""; echo $output; ?>

Maximum matches was .