From 3f2553880ad4803b32c630e5c68ba0b2717d1ee3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?tom=C3=A1s=20zerolo?= Date: Sun, 20 Nov 2022 14:53:10 +0100 Subject: [PATCH] now with histograms: to be debugged --- coinflip-histo.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 coinflip-histo.py diff --git a/coinflip-histo.py b/coinflip-histo.py new file mode 100755 index 0000000..24dfc9a --- /dev/null +++ b/coinflip-histo.py @@ -0,0 +1,20 @@ +#!/usr/bin/python3 + +import sys +from random import random +import matplotlib.pyplot as plot + +def flipcoins (n): + return [int(2*random()) for i in range(n-1)] + +if len(sys.argv) != 3: + print(f"Usage: {sys.argv[0]} \n") + exit(1) + +flips = int(sys.argv[1]) +repeats = int(sys.argv[2]) + +vals = [sum(flipcoins(flips)) for i in range(repeats - 1)] + +plot.hist(vals, bins=flips, align='left') +plot.show() -- 2.30.2