61 lines
2.0 KiB
Python
Executable File
61 lines
2.0 KiB
Python
Executable File
#! /usr/bin/python3
|
|
|
|
import random
|
|
import quantumrandom # pip3 install quantumrandom
|
|
|
|
sample = 1000000
|
|
die_min = 1
|
|
die_max = 6
|
|
max_amount = (die_max * 3) * sample
|
|
qseed = quantumrandom.get_data(); # get seed from quantum API
|
|
quantum_os_rand = random.SystemRandom(qseed[0])
|
|
dist_rl, dist_dl = {}, {}
|
|
i, rl_total, dl_total = 0, 0, 0
|
|
|
|
def roll():
|
|
#return random.randint(die_min, die_max) # bad: Pseudo-random
|
|
#return random.SystemRandom().randint(die_min, die_max) # better: OS random
|
|
return quantum_os_rand.randint(die_min, die_max) # good: OS with Quantum seed
|
|
#return quantomrandom.randint(die_min, die_max) # amazing: Slow, try 10 samples max
|
|
|
|
def drop_lowest(arr):
|
|
arr.remove(min(arr))
|
|
return arr
|
|
|
|
def reroll_lowest(arr):
|
|
arr.sort()
|
|
old_roll = arr.pop(0)
|
|
new_roll = roll()
|
|
if old_roll <= new_roll:
|
|
arr.append(new_roll)
|
|
else:
|
|
arr.append(old_roll)
|
|
return arr
|
|
|
|
while i < sample:
|
|
rl_set = sum(reroll_lowest([roll(), roll(), roll()]))
|
|
rl_total += rl_set
|
|
dist_rl[rl_set] = dist_rl.get(rl_set, 0) + 1
|
|
|
|
dl_set = sum(drop_lowest([roll(), roll(), roll(), roll()]))
|
|
dl_total += dl_set
|
|
dist_dl[dl_set] = dist_dl.get(dl_set, 0) + 1
|
|
i += 1
|
|
|
|
p_rl, p_dl = ((100 / max_amount) * rl_total), ((100 / max_amount) * dl_total)
|
|
|
|
print("3d{:d} Re-roll Lowest - {:d} samples\nDistribution (result : times)".format(die_max, sample))
|
|
for attribute, value in dict(sorted(dist_rl.items())).items():
|
|
print('{:d} : {:d}'.format(attribute, value))
|
|
print("{:.5f}% ({:d} of {:d}).\n".format(p_rl, rl_total, max_amount))
|
|
|
|
print("4d{:d} Drop Lowest - {:d} samples\nDistribution (result : times)".format(die_max, sample))
|
|
for attribute, value in dict(sorted(dist_dl.items())).items():
|
|
print('{:d} : {:d}'.format(attribute, value))
|
|
print("{:.5f}% ({:d} of {:d}).\n".format(p_dl, dl_total, max_amount))
|
|
|
|
if rl_total < dl_total:
|
|
print("4d{:d}dl rolled more by {:.5f}%".format(die_max, p_dl - p_rl))
|
|
else:
|
|
print("3d{:d}rl rolled more by {:.5f}%".format(die_max, p_rl - p_dl))
|