projects
/
susannes-git
/
mathe
/
stats
/
bernoulli.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
f66d196
)
now with histograms: to be debugged
author
tomás zerolo
<tomas@tuxteam.de>
Sun, 20 Nov 2022 13:53:10 +0000
(14:53 +0100)
committer
tomás zerolo
<tomas@tuxteam.de>
Sun, 20 Nov 2022 13:53:10 +0000
(14:53 +0100)
coinflip-histo.py
[new file with mode: 0755]
patch
|
blob
diff --git a/coinflip-histo.py
b/coinflip-histo.py
new file mode 100755
(executable)
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]} <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()