-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiceSim.py
41 lines (35 loc) · 1.2 KB
/
DiceSim.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
import random
import time
sidesOfDice = 6
rollsToDo = 100000000
resultsList = [0]
possibleOutcomes = 1
while possibleOutcomes < sidesOfDice:
resultsList.append(0)
possibleOutcomes += 1
if rollsToDo <= 1000000:
rollsDone = 0
while rollsDone < rollsToDo:
outcome = random.randint(0, sidesOfDice - 1)
resultsList[outcome] += 1
rollsDone += 1
print(f'Results of {rollsToDo} rolls:')
for item in resultsList:
print(f"There were {item} {resultsList.index(item) + 1}'s rolled ({item/rollsToDo*100}%)")
else:
start = round(time.time() * 1000)
rollsDone = 0
while rollsDone < rollsToDo:
outcome = random.randint(0, sidesOfDice - 1)
resultsList[outcome] += 1
rollsDone += 1
if rollsDone % 1000000 == 0:
print(f'Results of {rollsDone} rolls:')
for item in resultsList:
print(f"There were {item} {resultsList.index(item) + 1}'s rolled ({item/rollsDone*100}%)")
print(f'It took {round(time.time() * 1000) - start}ms to complete the last 1,000,000 rolls')
start = round(time.time() * 1000)
print()
print(f'Results of {rollsToDo} rolls:')
for item in resultsList:
print(f"There were {item} {resultsList.index(item) + 1}'s rolled ({item/rollsToDo*100}%)")