I have always wanted to create a lottery generator, either in Excel, Python, or R. I managed to find this tutorial (first published in 2011) on YouTube which creates a lottery generator using Microsoft Excel and basic VBA code. This tutorial is really well explained, and I was able to create a lottery generator in no time at all.
The image below is my version of the tutorial above. This has been updated though beacause the lottery now lets you pick from 59 numbers, than the original 49.
However, I wanted to create a euromillions generator which is based on chosing from five numbers (between 1 to 50), and two numbers (from 1 to 12) called Lucky Stars. This means that a number can appear twice on one ticket, therefore a modification of the excel spreadsheet neeeded to consider this.
The above is possible to do which requires creating a second rand() column based on the Lucky Stars numbers. The tweak to the VBA requires linking the lucky numbers to the columns in the generator tab using the following code to produce the numbers :
Sub euromillions_run() Worksheets("euromillions-generator").Range("A2:B51").Calculate Worksheets("euromillions-generator").Range("E2:F13").Calculate With Worksheets("euromillions-draw-sheet") Range("B5").Calculate Range("D5").Calculate Range("F5").Calculate Range("H3").Calculate Range("J5").Calculate Range("L5").Calculate Range("N5").Calculate End With End Sub
I’ll use this generator to produce some statistics based on actual lotto results.