From: tomás zerolo Date: Sun, 20 Nov 2022 13:53:10 +0000 (+0100) Subject: now with histograms: to be debugged X-Git-Url: http://git.tuxteam.de/gitweb/?a=commitdiff_plain;h=3f2553880ad4803b32c630e5c68ba0b2717d1ee3;p=susannes-git%2Fmathe%2Fstats%2Fbernoulli.git now with histograms: to be debugged --- 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()