From: tomás zerolo Date: Sun, 20 Nov 2022 15:35:22 +0000 (+0100) Subject: Two off-by-one errors X-Git-Url: http://git.tuxteam.de/gitweb/?a=commitdiff_plain;h=97cfeebd846825a3d0b922b080df3b8ca5d755e8;p=susannes-git%2Fmathe%2Fstats%2Fbernoulli.git Two off-by-one errors --- diff --git a/coinflip-histo.py b/coinflip-histo.py index 24dfc9a..2a737ce 100755 --- a/coinflip-histo.py +++ b/coinflip-histo.py @@ -5,7 +5,7 @@ from random import random import matplotlib.pyplot as plot def flipcoins (n): - return [int(2*random()) for i in range(n-1)] + return [int(2*random()) for i in range(n)] if len(sys.argv) != 3: print(f"Usage: {sys.argv[0]} \n") @@ -14,7 +14,7 @@ if len(sys.argv) != 3: flips = int(sys.argv[1]) repeats = int(sys.argv[2]) -vals = [sum(flipcoins(flips)) for i in range(repeats - 1)] +vals = [sum(flipcoins(flips)) for i in range(repeats)] plot.hist(vals, bins=flips, align='left') plot.show()