$i = 1;
$balance = 100.0; $init_balance = $balance;
$bet = 1.0;
$win_multiplier = 1.957; // SD 50%
$threshold = mt_getrandmax() / 2;
$won = 0; $lost = 0;
$high = $balance;
while ($balance > 0) {
printf("New iteration #%d, betting %f BTC\n", $i++, $bet);
$balance -= $bet;
$chance = mt_rand();
if ($chance < $threshold) {
printf("%d is below %d, you lose!\n", $chance, $threshold);
$lost++;
} else {
printf("%d is above or equals %d, you win!\n", $chance, $threshold);
$balance += $bet * $win_multiplier;
$won++;
}
printf("New balance: %f BTC\n", $balance);
$high = max($balance, $high);
}
printf("Initial balance: %f BTC\n", $init_balance);
printf("Final balance: %f BTC\n", $balance);
printf("Your highest balance in this game was %f BTC\n", $high);
printf("You won %d times and lost %d times (%f%% won)\n", $won, $lost, 100*$won / $i);
printf("It took me %d iterations to make you broke. Stop gambling!\n", $i);
?>