## Lottery Simulator

Back in the first programming course I took at the university level (intro to java) I got to thinking about the lottery. I ended up writing a simple program that did the following:

1. Read in 6 numbers provided by the user (between 1 and 49, as per the lottery in my province).
2. Have the program pick 6 numbers at random and compare them to my pick.
3. Loop until the program matches my pick and return the number of loops.

I didn’t have a point in the exercise, I just wanted to see if I could do it. At that point it was one of the more complicated things I had accomplished and I’d done it for myself, not for grades (which made it more awarding).

I’ve lost the source code for that program, but I’d recently become interested in that simulation, again. I’ve rewritten it in C and made it scalable with the pool of numbers to pick from (ie, 49) as well as the quantity of numbers to pick (ie, 6).

I’m interested in finding the average number of games to play, chance of winning a lottery based on pool size and pick size. In the standard lottery in Canada the pool size is 49 and the player picks 6 numbers. It’s a suckers’ tax. I’ll let you in on a secret. So far, the average number of games needed to play in order to win that lottery is 13.5 million games. Like, for example, when Coke tells you that you have a 1 in 6 chance of winning another bottle of Coke I am telling you that you have a 1 in 13,500,000 chance of winning the lottery. (edit: I’m aware that this is accomplished with the function n choose k that we learn in calculus. Googling 49 choose 6 gives the result 13,983,816)

I’ll get more into that later. Expect a “Science” page to open up here in the next little while with a portal to the simulation. So far I’ve written the code to run the stats, process them into mean, minimum and maximum values, and to plot the data and save them as nice images. The program also compiles the results into it’s own html page for easy viewing. About all that’s left now is to have the program index the pages and link them together for easier navigation.

And of course, the source code will be made available to all.

## Hello world!

That is the A-typical output from the first program learned in the first computer science course in university. Hello world!

If you’re a computer science student, this site is geared for you. I want to help you have more time to play games and spend less time on homework.

I’ve been there. I graduated with a Bachelor of Science majoring in Computer Science. I spent most of my time in class reading books or playing games (I recommend DEFCON or buying a DS). I didn’t get the best grades because of it, but I had plenty of time to do the things I wanted. And let’s face it, most of what you learn about computers and programming is the stuff you want to learn yourself on your own time.

So take what you can from this site if it’ll help you finish that homework assignment. I just ask that you abide by the rules set out by your university or professor. Most often they require you to quote your sources, so just include a comment with the n3wt0n! URL if required.

And remember, whether it’s homework or fun, there’s always science to do.

Staypressed theme by Themocracy