roulette-wheel

When your Roulette Simulator lies

Roulette is a frustrating game, and you can be easily lulled into a false sense of security if you believe the odds are in your favour, particularly when your strategy has worked in the past. So I wrote a Roulette Simulator, for testing my strategies. It is not pretty and doesn’t have any graphics but it will help me determine whether or not I’m as smart as I think I am.

At Perth Casino, a few years ago a few games of roulette changed from a bit of fun, with little money at risk, into a series of larger bets which I eventually lost. After a few $800 bets, I concluded the randomness of roulette will eventually bite you on your backside. A winning streak, a smiling face quickly morphed into horror, followed by an uncomfortable conversation with my wife in which I explained why I was betting $800 a spin. Thankfully she’s the best wife ever and said “Oh well, these things happen!”

For more on my increasing bets adventure see My Perth Casino Roulette Adventure.

Writing a Roulette Simulator

With subsequent visits, I’ve been perfecting my roulette skills and after a few hours, I usually have more cash than I started with. My winnings are promptly confiscated by my wife and fed it into slot machines; never to be seen again.

Having found a strategy, where the odds are in my favour I needed to convince my wife it was worth risking some hard-earned dollars. In such a situation what does any computer programmer do? They write a simulator and let the strategy play out. No, I’m not telling you what my strategy is!

What I discovered, was over shorter periods, like 30 minutes or an hour, money was consistently lost whereas over three or four hours, I came out in front. The laws of averages & probabilities were seemingly working in my favour.

The big problem, was the size of my wager and with small wagers come small returns. My younger brother used to say, “you must bet big to win big.” For a $30 bet, I’d make just $5 and there was still a chance I would lose my original wager completely. Part of my wager represented hedge-bets which got my money back. Needless to say, profiting was slow going, and I was repeating the same bet over and over. Not exciting at all.

Increasing wager improves profits but…

Increasing my wager from $30 up to $300 gives me a $50 return for a win with potential to lose $300. My less than superior mathematically-challenged brain concluded; “if a game is played every minute or two I could earn about $560 per hour.” Obviously this number only works if I actually win and in reality my strategy is more likely to return my original wager.

My simulator places imaginary bets on my chosen numbers and plays a game every 60 or 90 seconds. I let it run for four hours and it showed three times as many draws as wins and a few losses but ultimately returned good profits.

My random number generator was seeded using various methods such as /dev/random or /dev/urandom, and even Xorshift. I needed to ensure numbers generated were truly random and no discernible pattern emerged. Computers are not good a generating random numbers and they can be predicted reasonably easily. By seeding generators with similarly random 64 or 128 bit large numbers return values are less likely to be dodgy. Random.org provides more randomness by using atmospheric noise for seed values but I can’t be bothered writing additional code for making a connection to a remote site in order to get random numbers.

My simulator seemed to work brilliantly; but wait…

The downside was that in order for a complete test it need to run for four hours at a time over seven days. The $560 I mentioned earlier was the average profit over a number of sessions. After days of simulation my accumulated was just under $29,000. I even recorded results in a spreadsheet and I really hate spreadsheets and avoid them like the plague.

Screen shot of my spreadsheet

Things were going well but because I had made so many changes to my code it was getting harder to read & extremely messy. Originally I wasn’t bothered by untidy code as I’m never releasing it, but opted for a rewrite anyway. It needed to be better, neater, more readable and efficient. The rewrite took less than an hour and it looked nicer and gave me more information.

Again I started a four hour run and was expecting similar results but things were very different now! Something was wrong with one of the simulators but which one; old or new?

WTF – Roulette Simulator

I ran the old simulator again and, to my horror, there’s an error in adding up wins deducting losses & bets. After manually calculating wins, losses & draws the numbers varied from my bank balance and that is pretty f#&ked up. I still don’t know exactly why but clearly I am a shitty programmer despite 30 years experience! I expect what went wrong was after adding various strategies I confused which strategy was adding results up.

What I am certain of is the numbers in my newer version added up exactly right!

At $300 per spin you can lose a lot of money quickly and for each loss six wins are required to recover. An initial $1,200 balance is gone in just four straight losses while it takes 24 wins to recover.

Still small profits but…

The new simulator does show profits but smaller than the original. As I write this article it has been running for 37 minutes with 203 minutes remaining and shows a profit of $300. That is 5 wins, 33 draws and zero losses. No loses at this stage is unusual, but it does happen.

After the obligatory four hours I started the simulator again.

I grabbed a screenshot with 176 minutes remaining and surprisingly this round shows only one loss. One hour in usually shows three or four losses.

Roulette-Strategy-Simulator

The above shows everything I need to know. I started with $1,200 and a $300 wager over 240 minutes and there are 176 minutes remaining. One loss, 17 wins and 46 draws. The columns on the right represent All Numbers (#), Winners (+), Draws (0) and Losses (-).

Will my wife let me potentially throw away $1,200?

Truth be told I have not told her of my original simulator errors and am waiting until I’ve run more tests.

Even if profits are half what I had hoped for it still represents good money for sitting around drinking beer. I have no doubt she will be supportive as she always has been when I’ve come up with a hair-brained idea.

If you are interested you can read about why I want to join the Crown Casino Board here.

Update: I have created a site dedicated to roulette, take a look.