How to Generate 6+1 Lottery Numbers from Python
I am playing a different kind of raffle this year, one that use official South Korean lottery numbers. Usually these small group raffles use raffle tickets (like the ones in the featured image) then to pick out the winner, or play a bingo. This game is just like a lottery, only that they are not running the ball-pulling show. But that’s not really the point I’m getting at.
Because it’s just a raffle done on app, not an official state lottery, I’m guessing there was an honest oversight from the developer — whenever I run a “random” combination of 6 numbers*, I get the combinations that are starting with 1
, for nearly 8 out of 10. This isn’t a grand conspiracy, mind you; this is just a free raffle. But it seems comically improbable that I’m hitting 1
so many times.
* South Korean lottery uses total of 7 numbers, 6 regular and 1 bonus. The last bonus number is used to select the 2nd place.
So I wrote my own codes, following the rules of South Korean lottery system. The numbers are from 1
to 45
, total of 6
regulars and 1
bonus number. It’s running under the assumption the same number cannot be picked again; different lotteries will have entirely different rules.
#!/usr/bin/env python3
import random
min = 1
max = 45
count = 6
bonus = 1
poss = []
maxlen = len(str(max))
for idx in range(min, max + 1):
poss.append(str(idx).zfill(maxlen))
win = []
winbonus = []
for idx in range(count):
n = random.choice(poss)
win.append(n)
poss.remove(n)
n = random.choice(poss)
winbonus.append(n)
poss.remove(n)
print(sorted(win))
print(winbonus)
Needless to say, on my Python code, hitting 1
doesn’t happen as much. It does make me wonder what kind of mistake a personal finance app must have made. Again, this is just a fun raffle, and I don’t want to spook anyone. But, you can still totally use it for your own lottery games if you don’t want to pick a number. And the randomness of those numbers will be somewhat — not cryptographically random, but random enough — guaranteed.