Monday, 16 December 2013

Simple python lotto number picker

We had unusually big lotto the other day, so I wanted to play. I decided to write my own lucky number picker. This one picks 5 numbers out of 40 number pool, excludes last drawn number and returns your 5 number row in order.

import random   
from random import choice
for k in range(10): # number of row to print
    pick = list(range(1,41))  # size of pool 40 +1 
    numbers = [] 
    for j in range(5): 
        num = random.choice(pick) 
        pick.remove(num) # remove selected number from pool
    print sorted(numbers)   # return sorted row
All ideas about improving this code are welcome.