This simple PHP function I made simulates a gambler going to play roulette, always picking the same color. When he wins, he stays at the basic bet (1), when he loses, he doubles it until he wins.
I tried it over 50 spins, to 1000 spins, I always end up profitable.
How is that possible? Surely I got something wrong?
<?php
// starting at a 100
$bankroll = 100;
// our choice (one color throughout the entire session)
$choice = rand(0,1);
// just counting how many wins and losses
$wins = 0;
$losses = 0;
// amount of the wager
$amount = 1;
$output = '';
echo 'START BR: £' . $bankroll . '<br>';
// We're playing 100 spins
for ($i=0; $i < 100; $i++) {
$output .= $i . '. ';
$output .= 'Betting £' . $amount . ' (';
// Reduce the bankroll by the wager
$bankroll = $bankroll - $amount;
// Checking if we won, or lost
$result = $choice = rand(0,1) ? true : false;
// If we win: increase bankroll by wager times two and go back to betting one.
if( $result ) {
$output .= '<span style="color: darkgreen;">won</span>';
$bankroll = $bankroll + ( $amount * 2 );
$amount = 1;
$wins++;
}
// If we lose: next bet will be the double.
if( !$result ) {
$output .= '<span style="color: red;">lost</span>';
$amount = $amount * 2;
$losses++;
}
$output .= ')<br>';
$output .= 'Bankroll: £' . $bankroll;
$output .= '<br><br>';
}
echo 'END BR: £' . $bankroll . '<br>';
echo 'DIFF: £' . intval( $bankroll - 100 ) . '<br><br>';
echo 'WINS: ' . $wins . '<br>';
echo 'LOSSES: ' . $losses . '<br>';
echo '<br><hr><br>';
// Output the log
echo $output;
Aucun commentaire:
Enregistrer un commentaire