# Betting strategy simulation

I lately got interested into betting systems, dice strategies and algorithms. I took some time to think about it and eventually ended up with an algorithm of my own.

Considering that I don't have unlimited money that would allow me to test it on a real dice betting site (duh), I have coded a simulation that allows me to run my algorithm in an environment that reproduces those websites.

Although I have not tested it in extreme conditions (really large number of rolls) it seems to work pretty well, and I never got my simulation going "out of bankroll" or even finish the algorithm with less bankroll than it started with.

I have commented this so it is clear to everyone what I was thinking and why is every operation doing.

public static void Main(string[] args)
{
simulation1(0.000001, 1.1, 1.09, 10.9, 0.01, 10);
}/*                |       |     |    |     |     L-->  This is the number of "Big Wins" you want to play. The simulation will
|       |     |    |     |               play until that number is reached.
|       |     |    |     L------->   This is your initial Balance. The simulation will stop and warn you if
|       |     |    |                     any bet gets too big for your actualBalance, but you gotta start
|       |     |    |                     with something.
|       |     |    L------------->   This is The multiplicator after loss. Basically, when you lose, the
|       |     |                          next bet(s) will be multiplicated by this amount until you win again,
|       |     |                          which will be a "Big Win" and is gonna reset your iterations.
|       |     L------------------>   This is the multiplicator after win. While you have not lost yet (meaning
|       |                                that since last "Big Win" you are on a straight win streak) every
|       |                                next bet will be multiplicated by this amount.
|       L------------------------>   This is the Payout of the bets you are playing.
L-------------------------------->   Finally, that is the value of your first base bet. Every time a "Big Win"
is achieved, your bets will be reset to this value and will grow again
until next one.
*/

//  Here is the 'brain' of the algorithm. I have included in it some commented lines, noted "C/U" that you can uncomment to see datas
//  in the shell as the program runs. For example, what number did you roll, was it a win or a loss, what "while" loop were you in,
//  etc... Be careful, although uncommenting those lines will not change anything about the running capacity of the algorithm, the more
// you display, the less easy to read it becomes..
public static void simulation1(double base_bet, double payout, double mult_post_victoire, double mult_post_defaite, double Balance, int nb_victoires_avt_stop)
{

Console.WriteLine("----------START---------- ");                                // C/U //   shows where the loop begins.
Console.WriteLine("number of remaining Big Wins = " + nb_victoires_avt_stop);   // C/U //   displays the number of remaining Big wins, which is
//          also the remaining number of loops.

if (nb_victoires_avt_stop == 0)                                                 //          Stopping Condition. If the number of big wins reach
//          zero, you stop the algorithm and are done.
{
Console.WriteLine("----------FINISH----------"); Console.WriteLine("balance = " + Balance);     // C/U //   shows where the program stops to
//          run, and displays your final Balance; if it's bigger
//          than your initial balance, without having returned
//          any errors during the run, no bets have been too high
//          for your bankroll -> it's a success.
for (int i = 0; i < 10; i++)
{
Console.WriteLine("");                                                  // C/U //   some blank lines before starting again. It's here
//          mostly to keep it easily readable when you simulate
//          repeatedly.
}
return;
}

double chance_victoire = (99 / payout);                                         //          Your chance of winning, influed by the payout you
//          defined. Here it is '99' because the house edge is
//          considerated to be 1%. You can adjust it for a
//          different house edge if you want.
Console.WriteLine("chance to win = " + chance_victoire + "%");                  // C/U //   displays your chance to win.

bool A_perdu = false;                                                           //          this bool starts at false ; as soon as a loss is
//          encountered, it switches to true, and changes the
//          operating "while" loop.
double bet = base_bet;                                                          //          your base bet. it is gonna grow, but you've got to
//          keep the value of "base_bet" variable untouched to
//          reset at every big win, so we make a clone for the
//          actual turn.
//Console.WriteLine("A_perdu = "+ A_perdu);

while (A_perdu == false)                                                        //          This loop is active while you have not reached a lose
{
//Console.WriteLine("LOOP 1 ");                                             // C/U //   debug tool -> in case you want to know, at every bet,
//          in which loop you are. Should write LOOP 1 until you
//          lose. Then you wont get into that loop until next
//          reset.
//Console.WriteLine("bet = " + bet);                                        // C/U //   displays your bet before each roll. You can watch it
Thread.Sleep(1);                                                            //          Very Important to keep the simulation running without
//          bugs. If we dont wait, the next bunch of rolls will
//          have the same value (because random is pseudo-random,
//          based on time, and if it is too fast you have the
//          time to make several bets before changing to next
//          millisecond, which will change the random value
double tirage = RandomNumber();                                             //          Rolls a random number between 0 and 1
//Console.WriteLine("roll = " + tirage);                                    // C/U //   Display your roll. In case you want to verify that no
//          rolls ar identical, or predictable, or unevenly
//          reparted.
Balance -= bet;
if (Balance <= 0)                                                           //          after each bet, if your balance is negative, it means
//          that "in real conditions" you wouldn't have had
//          enough bankroll.
{
Console.WriteLine("ERROR BALANCE NEGATIVE");
return;
}
if (tirage < (chance_victoire / 100))                                       //          Calculates if your roll is a winning roll or not.
{
Console.WriteLine("win");                                               // C/U //   Displays if you roll is winning.
Balance += (payout * bet);
bet *= mult_post_victoire;                                              //          Multiply bet by the value you chose, while its a win
//          streak it keeps looping in this "while"
//Console.WriteLine("balance_win = " + Balance);                        // C/U //   watch your balance evolve in real time.
}
else
{
Console.WriteLine("-----------------------lose");                       // C/U //   Displays if your roll is losing.
bet *= mult_post_defaite;                                               //          multiply your bet by the value after lose you defined
//Console.WriteLine("balance_lose = " + Balance);                       // C/U //   Watch your balance evolve in real time
A_perdu = true;                                                         //          switches the bool to true, to enter the second loop.
}
}

while (A_perdu == true)                                                         //          You enter this loop once you have lost one time.
{
//Console.WriteLine("LOOP 2 ");                                             // C/U //   If you want to see in which loop you are.
//Console.WriteLine("bet = " + bet);
double tirage = RandomNumber();
//Console.WriteLine("roll = " + tirage);
Balance -= bet;
if (Balance <= 0)
{
Console.WriteLine("ERROR BALANCE NEGATIVE");
return;
}
if (tirage >= (chance_victoire / 100))                                      //          While you keep losing, you keep multiplying your bet
//          by the same amount.
{
Console.WriteLine("-----------------------lose");
bet *= mult_post_defaite;
//Console.WriteLine("balance_lose = " + Balance);
}
else                                                                        //          As soon as you win, it is a "Big Win", the whole turn
//          is finished, you can reset the algorithm.
{
Console.WriteLine("win");
Balance += (payout * bet);
//Console.WriteLine("balance = " + Balance);
simulation1(base_bet, payout, mult_post_victoire, mult_post_defaite, Balance, nb_victoires_avt_stop - 1);   // That resets the simulation
//          with slightly different parameters : your actual
//          balance as value os "initial balance", and the
//          remaining number of big wins decreased by one.
return;                                                                 //          at some point the last iteration, with remaininng big
//          wins == 0, will return, so like a waterfall every
//          precedent function will return. You can see it like
//          an "inception dreams in dreams" unless there, it is a
//          function in a function in a function... when the very
//          last function ends, it comes back to the immediate
//          previous one, which does the same until we reach the
//          first one, that returns the final value of the
//          simulation.
}
}
}

public static double RandomNumber()             //  This function is here to generate a random number between 0 and 1, and reproduce ("emulate") the
//  behavior of any dice site's roll system.
{
int seed = DateTime.Now.Millisecond;
double number;
Random rnd = new Random(seed);
number = rnd.NextDouble();
return number;
}


Is my simulation really doing its job properly? Are my dice rolls really random? Is my strategy working as it should, or am I missing something?

I also ran it into Tutorialspoint coding ground here (same code, uncommented).

• "or even finish the algorithm with less bankroll than it started with." <-- that's an indication that something is flawed. A gambling business would go out of business if they had to pay out more than what was coming in. You are always more likely to loose than to win. – Sumurai8 Aug 8 '16 at 16:48
• If we are talking the standard craps table in a casino, there should be 2 random numbers generated, one for each die, values 1 to 6 for each. I also don't see where the different types of bets are placed, such as play the line, bet the odds, the come bar. I can create a table easily of the odds of 2 through 12, I don't see how this helps. – pacmaninbw Aug 8 '16 at 17:04
• You get +1 just for the effort of writing the comments. This is really good explained. – t3chb0t Aug 8 '16 at 20:31
• @Sumurai8 Yeah I know, i'm not trying to get the odds in my favor, i know that is not possible, and that I am not the first one to try, I can't pretend to succeed with my modest capacities after everyone else agreed that favors are always to the house. What I waned to say is that, so far, I didnt see it losing with those particular parameters :) – Maxime B Aug 9 '16 at 9:33
• @pacmaninbw I'm talking about higher-lower gambling sites, like Bitsler.com or PrimeDice.com. They use user and server seeds and a hash function to obtain the random number, but this is just a simulation - i only need a random roll to make the simulation viable imo - tell me if I'm wrong though, i'm not omniscient .. – Maxime B Aug 9 '16 at 9:37

### Random number generation

Your random number function has a big problem. It is currently reseeding itself to DateTime.Now.Millisecond on each call. Assuming your program runs fairly quickly, this means that you will generate the same random number over and over until the time advances to the next millisecond. You can test this by printing out a series of random numbers and seeing what you get.

To fix this, you should create a single Random object from a single seed, and then reuse the same object to generate all of your random numbers.

• Actually, I had this problem - and I have been able to see it because of this line //Console.WriteLine("roll = " + tirage); That is why I added a "Thread.Sleep(1);" right before every new roll. That causes the program to wait 1ms before continuing (as far as I understood) and therefore each roll is different from any other – Maxime B Aug 16 '16 at 12:01
• @MaximeB Ah, but if you fix the problem, you wouldn't have to use Sleep(), and then your program could run thousands of times faster. – JS1 Aug 16 '16 at 19:05

You have a 90% chance to win each roll? Of course your program is doing well. However you will not find any site which gives you this level of probability for winning. Otherwise they would surely be bankrupt by now.

You need to rethink how you are calculating the win/loss.

• as you can see here you can absolutely have this level of probability for winning, and even more (up to 98% of chance of winning, which gives a payout of 1.0102 actually). They keep themselves from going bankrupt by keeping 1% (or whatever number the house edge is) of every bet you win. What do you mean by need to rethink how I am calculating the win/losses ? – Maxime B Aug 17 '16 at 10:23
• Where does it say that on the link you provided? I see nothing about win probability? – Milney Aug 17 '16 at 12:16
• I suggest you read up on some probability mathematics: en.wikipedia.org/wiki/Gambler%27s_fallacy – Milney Aug 17 '16 at 12:21
• it is a link to one of those websites. Once logged in, you can see that you can set the win chance up to 0.98, which is a proof that a 0.9 win chance is possible. I know about gambler's fallacy, thanks. but you're still not explaining in what way I should rethink the calulations – Maxime B Aug 17 '16 at 12:43
• If you read up on the Gamblers Fallacy, and you are convinced the rolls are truly random... then i do not see why you are bothering to develop something like this – Milney Aug 17 '16 at 12:51