Skip to content

Instantly share code, notes, and snippets.

@SoundLogic
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SoundLogic/98a98ca07da751fe8499 to your computer and use it in GitHub Desktop.
Save SoundLogic/98a98ca07da751fe8499 to your computer and use it in GitHub Desktop.
why casinos have maximum (and strategically relative minimum) bets (you would need a pretty hefty bankroll for this even if you start with a $5 base bet)
using System;
namespace Roulette
{
class Program
{
static void Main(string[] args)
{
var r = new Random();
double highestCumulativeLossPointOfAnySimulation = 0;
double totalCumulativeProfit = 0;
int highestConsecutiveLossesInAllSimulations = 0;
for (int i = 0; i < 1000; i++)
{
// if you have billions of dollars you can maybe set n a little higher
// n must be >= 1
double n = 1.1;
int maxIterations = 1000;
double currentProfit = 0;
double baseBet = 10;
double highestBet = baseBet;
double probabilityPercentOfWin = 16.0 / 38.0 * 100;
//double probabilityPercentOfLoss = 1 - (probabilityPercentOfWin/100);
double highestCumulativeLossPoint = currentProfit;
// same as the odds you would get this far without losing if you don't play
// essentially showing in simple mathematical terms that "you gotta pay to play"
int mostConsecutiveLossesInCurrentSimulation = 0;
for (int j = 0; j < maxIterations; j++)
{
// reset
bool won = false;
double currentBet = baseBet;
int consecutiveLosses = 0;
while (!won)
{
if (currentBet > highestBet)
{
highestBet = currentBet;
}
currentProfit -= currentBet;
if (currentProfit < highestCumulativeLossPoint)
{
highestCumulativeLossPoint = currentProfit;
if (highestCumulativeLossPoint < highestCumulativeLossPointOfAnySimulation)
{
highestCumulativeLossPointOfAnySimulation = highestCumulativeLossPoint;
}
}
double outcome = r.Next(0, 100);
outcome += (Convert.ToDouble(r.Next(0, 1000000)) / 1000000);
if (outcome <= probabilityPercentOfWin)
{
currentProfit += 2 * currentBet;
totalCumulativeProfit += currentProfit;
won = true;
}
else
{
consecutiveLosses++;
if (consecutiveLosses > mostConsecutiveLossesInCurrentSimulation)
{
mostConsecutiveLossesInCurrentSimulation = consecutiveLosses;
}
currentBet = currentBet + n * currentBet;
}
}
}
if (mostConsecutiveLossesInCurrentSimulation > highestConsecutiveLossesInAllSimulations)
{
highestConsecutiveLossesInAllSimulations = mostConsecutiveLossesInCurrentSimulation;
}
Console.WriteLine("Simulation #{0}", i);
Console.WriteLine("______________________________");
Console.WriteLine("Total profit: {0}", currentProfit.ToString("C"));
Console.WriteLine("Highest bet: {0}", highestBet.ToString("C"));
Console.WriteLine("Highest cumulative loss (total amount of money you would need to \"beat the system\"): {0}", highestCumulativeLossPoint.ToString("C"));
Console.WriteLine( "Most consecutive losses (assume you keep betting black, but only red or green come up consecutively): {0}", mostConsecutiveLossesInCurrentSimulation );
Console.WriteLine(String.Empty);
}
Console.WriteLine("Highest cumulative loss in all the simulations that were run: {0}", highestCumulativeLossPointOfAnySimulation.ToString("C"));
Console.WriteLine("Total cumulative profit: {0}", totalCumulativeProfit.ToString("C"));
Console.WriteLine("Highest consecutive losses in all simulations: {0}", highestConsecutiveLossesInAllSimulations);
Console.ReadKey();
}
/*
Result of 20 simulations at n = 1.1 (note that the highest bet
is just shown to illustrate the kind of risk you're dealing with),
but either way the point is that each of the below simulations
result in a profit granted the volatility suggests if you have
the bankroll to stomach the risk you probably don't need to take the risk
In a thousand simulations, the highest cumulative loss got up to $1,032,974,407.67
That said, the total cumulative profit was $172,400,244,529.76
... but if you have the money to fund those kinds of losses, Bernoulli's Marginal
Utility comes into play: http://en.wikipedia.org/wiki/Marginal_utility
Simulation #0
______________________________
Total profit: $154,551.00
Highest bet: $1,430,568.69
Highest cumulative loss (total amount of money you would need to "beat the system"): ($2,721,654.21)
Simulation #1
______________________________
Total profit: $21,526.50
Highest bet: $16,679.88
Highest cumulative loss (total amount of money you would need to "beat the system"): ($14,634.25)
Simulation #2
______________________________
Total profit: $87,237.33
Highest bet: $681,223.19
Highest cumulative loss (total amount of money you would need to "beat the system"): ($1,289,454.15)
Simulation #3
______________________________
Total profit: $41,405.91
Highest bet: $154,472.38
Highest cumulative loss (total amount of money you would need to "beat the system"): ($275,364.42)
Simulation #4
______________________________
Total profit: $35,295.87
Highest bet: $35,027.75
Highest cumulative loss (total amount of money you would need to "beat the system"): ($55,094.02)
Simulation #5
______________________________
Total profit: $44,652.44
Highest bet: $154,472.38
Highest cumulative loss (total amount of money you would need to "beat the system"): ($285,481.48)
Simulation #6
______________________________
Total profit: $25,132.10
Highest bet: $35,027.75
Highest cumulative loss (total amount of money you would need to "beat the system"): ($59,000.10)
Simulation #7
______________________________
Total profit: $24,764.42
Highest bet: $35,027.75
Highest cumulative loss (total amount of money you would need to "beat the system"): ($58,111.16)
Simulation #8
______________________________
Total profit: $41,576.30
Highest bet: $154,472.38
Highest cumulative loss (total amount of money you would need to "beat the system"): ($287,352.82)
Simulation #9
______________________________
Total profit: $78,780.55
Highest bet: $324,391.99
Highest cumulative loss (total amount of money you would need to "beat the system"): ($618,858.16)
Simulation #10
______________________________
Total profit: $33,159.77
Highest bet: $73,558.28
Highest cumulative loss (total amount of money you would need to "beat the system"): ($117,927.22)
Simulation #11
______________________________
Total profit: $33,356.50
Highest bet: $35,027.75
Highest cumulative loss (total amount of money you would need to "beat the system"): ($47,784.42)
Simulation #12
______________________________
Total profit: $43,539.77
Highest bet: $73,558.28
Highest cumulative loss (total amount of money you would need to "beat the system"): ($123,657.28)
Simulation #13
______________________________
Total profit: $45,424.23
Highest bet: $154,472.38
Highest cumulative loss (total amount of money you would need to "beat the system"): ($284,748.21)
Simulation #14
______________________________
Total profit: $38,620.49
Highest bet: $154,472.38
Highest cumulative loss (total amount of money you would need to "beat the system"): ($291,360.24)
Simulation #15
______________________________
Total profit: $169,231.62
Highest bet: $1,430,568.69
Highest cumulative loss (total amount of money you would need to "beat the system"): ($2,706,170.98)
Simulation #16
______________________________
Total profit: $28,443.49
Highest bet: $73,558.28
Highest cumulative loss (total amount of money you would need to "beat the system"): ($135,534.03)
Simulation #17
______________________________
Total profit: $69,819.12
Highest bet: $324,391.99
Highest cumulative loss (total amount of money you would need to "beat the system"): ($586,217.03)
Simulation #18
______________________________
Total profit: $24,632.33
Highest bet: $16,679.88
Highest cumulative loss (total amount of money you would need to "beat the system"): ($29,136.90)
Simulation #19
______________________________
Total profit: $48,867.44
Highest bet: $154,472.38
Highest cumulative loss (total amount of money you would need to "beat the system"): ($294,835.50)
*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment