Every inspiring programmer needs good projects to sharpen his or her skill set. I decided that a lottery program would be a great way to play around with some new functions, and learn about the random number generator in c++.
One night I was poking around the Powerball website and found the past winning numbers. I then realized that the winning numbers text file download link never changed from the website, and even better the layout of the file never changed. Since this plain text version is available on the website for download, I was able to code into the program the file download so with each new drawing you can tell it to grab the latest file, neat!
With the groundwork complete, I was ready to start messing around with the random number generator. Anyone who has worked with a computer random number generator knows that the numbers generated are never truly “random” because the generation from one number to the next is based on CPU clock cycles. Basically, if I request a new random number from the random number generator in c++ exactly every x milliseconds the result will basically be the same because time wise it lands on the same clock cycle. I imagine this is quite an issue for casino game developers since all slot machines, etc are now electronic these days. Just a carefully timed rhythmic pull of the handle could be enough to hit a second or third jackpot after winning big. I am exploring a couple of different solutions for this, one being using the random number generator in c++ and having it generate hundreds of thousands of numbers before landing on a choice using loops to create random timers. Another solution is using the powerball drawings itself to calculate how “random” the balls are being drawn and apply the randomness as a timed delay between generating random numbers.
So now that I have a generated drawing does it match up and win against the numbers drawn so far? The likely answer is no, so what I’m going to do is see how many times it takes to generate a winning number that matches whats in the plain text file. I will do that hundreds of times, each time recording the number of times it takes to generate a winner. If a fairly consistent number emerges allowing us to take an average that would be ideal, then we use that number to run the drawing generator x amount of times before spitting out a final set of numbers. In theory these are the numbers you would want to buy over the counter and hopefully win.
Once I have enough of the program written I will post it up for free download, it will be compiled for Linux X86, and Solaris SPARC. I will also have the source code available for a small fee ($2.00.. .. . Hey, I want to buy a powerball ticket!) so if you want to cheat on your homework assignment for programming class it’ll cost ya 😛 .
When will it be done? It will probably take another month, the random number generation portion takes significant CPU cycles to accomplish when attempting to make it truly “random” so I am looking at learning how to spawn additional threads / processes and utilize more than once CPU to complete the generation.
The screen shot above shows it in most basic form. Version .01 LOL .. Yeah this program is mostly just for fun, but full of learning or me. Maybe someone will win from using it, and leave a large tip. Looking at the generated drawings above, you can see that the third drawing listed isn’t quite “randomly generated” it definitely needs additional work.
Well for now I hope y’all enjoyed this little read, more is coming soon.