Skip to content

Instantly share code, notes, and snippets.

@aboueleyes
Created September 7, 2021 19:45
Show Gist options
  • Save aboueleyes/bd1534a75da78a568c5412dc676a137f to your computer and use it in GitHub Desktop.
Save aboueleyes/bd1534a75da78a568c5412dc676a137f to your computer and use it in GitHub Desktop.
#!/usr/bin/python3.9
from random import randint
import matplotlib.pyplot as plt
from signal import SIGINT, signal
MAX = 9500009900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
counts = []
def handler(_, __):
"""Handle SIGINT signals"""
print(f"num of trails : {len(counts)}")
plt.hist(counts)
plt.show()
def get_random_between(x):
c = 0
while True:
c += 1
if x == MAX:
return c
else:
x = randint(x, MAX)
def main():
signal(SIGINT, handler)
count = 0
while not count in range(1, 200):
x = randint(1, MAX)
count = get_random_between(x)
counts.append(count)
print(f"{count=}")
print(f"num of trails : {len(counts)}")
plt.hist(counts)
plt.show()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment