-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmegaball_ticket_gen.py
64 lines (53 loc) · 1.26 KB
/
megaball_ticket_gen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python
from multiprocessing import Process, Manager
from random import shuffle,randint
import time
import argparse,sys,os
parser = argparse.ArgumentParser(description='MegaMillions Random Number generator')
parser.add_argument('-t', dest='tickets', type=int, default=1, help='Number of Tickets')
args = parser.parse_args()
tickets=1
def shuffle_balls(vB):
try:
Ctr=0
while (True):
try:
shuffle(vB)
except Exception, e:
pass
time.sleep(0.001)
except Exception, e:
print ("Error in shuffleballs")
print (len(vB))
def popb(vB, Res):
Ctr=0
values=""
BallsCnt=len(vB)
while (Ctr < 5):
rgen=randint(1, int(BallsCnt))-1
rval=vB.pop(rgen)
Res[Ctr]=rval
values=values + " " + str(rval)
BallsCnt=BallsCnt-1
Ctr=Ctr+1
time.sleep(1)
while (tickets <= args.tickets):
with Manager() as manager:
Balls = manager.list( range(1,71) )
MBalls = manager.list( range(1,26) )
Res = manager.list( range(1,7) )
p1 = Process(target=shuffle_balls,args=(Balls,))
p1.start()
p2 = Process(target=shuffle_balls,args=(MBalls,))
p2.start()
time.sleep(2)
p = Process(target=popb,args=(Balls, Res,))
p.start()
p.join()
ri = randint(1, 25)-1
rval = MBalls[ri]
Res[5] = rval
print (Res)
p1.terminate()
p2.terminate()
tickets=tickets+1