Skip to content

Instantly share code, notes, and snippets.

@cdmoyer
Created August 16, 2010 23:37
Show Gist options
  • Save cdmoyer/527986 to your computer and use it in GitHub Desktop.
Save cdmoyer/527986 to your computer and use it in GitHub Desktop.
$chance = 30;
$total = 0;
$times = 0;
for ($i=0; $i<500000; $i++) {
$seen = 0;
for ($t = 0; $t<15; $t++) {
$roll = int(rand(100) + 1);
if ($roll < $chance) { $seen++; }
elsif (($t == 4 && $seen == 0) || ($t == 9 && $seen == 1) || ($t == 14 && $seen == 2)) { $seen++ ; }
if ($seen == 3) {
$total += $t;
$times++;
last;
}
}
}
printf("%d tries = avg %.2f", $times, $total / $times) . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment