Created
September 7, 2021 19:45
-
-
Save aboueleyes/bd1534a75da78a568c5412dc676a137f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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