now with histograms: to be debugged
authortomás zerolo <tomas@tuxteam.de>
Sun, 20 Nov 2022 13:53:10 +0000 (14:53 +0100)
committertomás zerolo <tomas@tuxteam.de>
Sun, 20 Nov 2022 13:53:10 +0000 (14:53 +0100)
coinflip-histo.py [new file with mode: 0755]

diff --git a/coinflip-histo.py b/coinflip-histo.py
new file mode 100755 (executable)
index 0000000..24dfc9a
--- /dev/null
@@ -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]} <flips> <repeats>\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()