Hitting the Powerball - An Interactive Simulation

Note: This has been updated to reflect the changes in the ranges for the numbers.

The powerball lottery is big right now, and it got me to thinking about how unlikely it is to win (that's nothing new).  The odds of winning are about one in 175 million.  Assuming about 100 drawings a year, and if you played every time, this means that you might expect to win once about every 1.75 million years.  That's a long time between winnings.

Anyway, I put together a simple statistical simulation (still a work in progress) that lets you run experiments with how long it might take your numbers to hit the jackpot.  It's on googledrive here.

Feel Lucky?
Try it yourself on google drive here 

The simulation uses a web worker to perform the simulation - it just draws the numbers over and over until the number hits or you give up.  It uses "Robert Floyd's algorithm" to pick the 5 distinct numbers in the range 1-59 (see here for a starting place for this tiny but clever algorithm) .  One could also more quickly determine whether you win for a given drawing by simply sampling from a Bernoulli distribution independent of actually modeling each of the balls being picked, but it seemed more interesting to go ahead and implement the individual components of the actual process that occurs in reality.

While of course the javascript is exactly the same on all browsers, I am noticing differences in how often it seems to "hit" across the browsers.  Chrome seems to take longer for some reason.  This might be an artifact of something off in this (simple!) implementation, or due to low-level differences in the browsers themselves, but it seems to be a real difference I need to look into more.  Safari seems to behave more reasonably, but that is a qualitative assessment at the moment. Update: I am now using version 2.1 of the random number generator by David Bau  (seedrandom.js).

The dates get big.  This hit some weirdness in the date formatting in Chrome, which doesn't seem to like it if the year gets above about 276,000 A.D.  I guess that's a reasonable edge case for Chrome to consider low priority.  Anyway, I had to make use of the fact that the Gregorian calendar repeats every 400 years to get around this.

It would be nice to add some additional visualization components to this - a dynamic graph showing you move out in time, occasionally almost hitting it big, and all the while displaying the amount spent to date.  This would help drive the simple point home, but I think seeing those crazy looking years in this initial version does, too.

No comments:

Post a Comment

Popular Posts