Skip to content

Instantly share code, notes, and snippets.

@richiverse
Last active March 18, 2023 05:06
Show Gist options
  • Save richiverse/a42ca04d6734a345850f to your computer and use it in GitHub Desktop.
Save richiverse/a42ca04d6734a345850f to your computer and use it in GitHub Desktop.
Python powerball number generator
#!/usr/bin/env python
"""
If you happen to win, I only ask for a measly 1% tip. ;)
To run, save this file and run it by typing the following in your terminal:
python powerball.py
"""
from pprint import pprint as pp
import random
def powerball():
drum1 = list(range(1,70))
drum2 = list(range(1,27))
white_balls = []
for _ in range(5):
choice = random.SystemRandom().choice(drum1)
drum1.pop(drum1.index(choice))
white_balls.append(choice)
white_balls = sorted(white_balls)
return white_balls + [random.SystemRandom().choice(drum2)]
try:
budget = int(int(input('What is your powerball budget? (Number must be multiple of 2)'))/2)
except:
budget = 1
pp(list(powerball() for i in range(budget)))
@forrie
Copy link

forrie commented Mar 5, 2017

A suggestion mod you might make is to capture http://www.powerball.com/powerball/winnums-text.txt (which is always updated) and run a comparison, against those results, to ensure the generated number doesn't match a previous number that won.

@Weryhjkoojtfr224r
Copy link

Ee

@Weryhjkoojtfr224r
Copy link

26-27-43-61-69 (4) next predictions powerball

@9Digimark
Copy link

from pprint import pprint as pp
import random

def powerball():
drum1 = list(range(1,70))
drum2 = list(range(1,27))
white_balls = []

for _ in range(5):
    choice = random.SystemRandom().choice(drum1)
    drum1.pop(drum1.index(choice))
    white_balls.append(choice)
white_balls = sorted(white_balls)
return white_balls + [random.SystemRandom().choice(drum2)]

try:
budget = int(int(input('What is your powerball budget? (Number must be multiple of 2)'))/2)
except:
budget = 1

pp(list(powerball() for i in range(budget)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment