Monday 5 January 2015

Simulating a coin toss in excel

I guess when you start to look at gambling theories or probabilities the natural place to start is the coin toss.

This relates especially well to roulette as a Heads or Tails coin toss kinda relates to Red or Black (not quite because of those pesky zeroes and double zeroes (and some other mechanical factors)).

Although Excel won't produce necessarily a true random number (it's a pretty poor random number generator (will discuss in another article), for our sake it will do.

Generating a random number between two values

The first thing we need to do is get excel to generate a random number between 2 values.   One number to represent heads and another to represent tails.   In this case 0 and 1.   0 will represent Heads and 1 will represent tails.

To do this

1) Open Excel
2) Open a new Workbook
3) Click on any cell and in the formula bar type in the following function

=RANDBETWEEN(0,1)

And here is how this looks on my machine (I'm using excel on a Mac)
















As you can guess from the formula, it randomly produces a number between 0 and 1 which funnily enough would be the values 0 and 1.   

Making it say Heads or Tails

As you can guess from the formula, it randomly produces a number between 0 and 1 which funnily enough would be the values 0 and 1.   

It would be cooler if it said Heads or Tails rather than 1 or 0.   And it's pretty easy to do in Excel.   We'll just use the IF formula.

So in your cell, just replace the previous formula with this.

=IF(RANDBETWEEN(0,1) = 0,"Heads","Tails")

And this will now check the randomly generated number, and if it's 0, it will display Heads in the cell, and if it's 1, it will display 1.

And here is how this looks on my machine















Generating lots of numbers

So we've generated one simulated coin toss but we obviously want to generate lots of numbers.  So to do that all we need to do is grab our cell by the bottom right hand corner and drag down.

And now you can see below, i've generate 20 coin tosses using the above method.


























Pretty easy to do right.   And we can use this in the future do lots of things.   Pick cards randomly, perform probability calculations etc.  Test for yourself if magic betting systems such as martingale is a good idea (btw it's not).

Google Docs

And the exact same thing works in Google Docs.

Hope you found this useful



10 comments:

  1. Excel is a software program from Microsoft basic excel for beginners that is a part of Microsoft Office. Excel calculations is compiled for making and altering spreadsheets that are spared with a .xls expansion. It's general uses in corporate cell-based figuring, turn tables, and different diagramming devices. With an Excel spreadsheet, you could make a month to month spending plan, track costs of doing business, or sort and compose a lot of information calculations in spreadsheets of Excels.

    ReplyDelete
  2. Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. slotxo

    ReplyDelete
  3. I know this is one of the most meaningful information for me. And I'm animated reading your article. But should remark on some general things, the website style is perfect; the articles are great. Thanks for the ton of tangible and attainable help. pgslot

    ReplyDelete
  4. Thank you so much as you have been willing to share information with us. We will forever admire all you have done here because you have made my work as easy as ABC. สล็อตXO

    ReplyDelete
  5. This is such a great resource that you are providing and you give it away for free. ku คาสิโน

    ReplyDelete
  6. Great post, you have pointed out some excellent points, I as well believe this is a very superb website. เซ็กซี่บาคาร่า

    ReplyDelete
  7. All your hard work is much appreciated. Nobody can stop to admire you. Lots of appreciation. สมัครบาคาร่า

    ReplyDelete
  8. Fantastic blog! Do you have any tips and hints for aspiring writers? I’m planning to start my own website soon but I’m a little lost on everything. Would you propose starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m completely overwhelmed .. Any suggestions? Many thanks! ไพ่บาคาร่า

    ReplyDelete
  9. Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks IDN Poker

    ReplyDelete
  10. I am impressed. I don't think Ive met anyone who knows as much about this subject as you do. You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here. slot online

    ReplyDelete