import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.patches import Rectangle
import timeit
import random
import sys


clock = timeit.default_timer

fig, ax = plt.subplots()

if len(sys.argv) == 1:
    n = 50
    at_a_time = 1
elif len(sys.argv) == 2:
    n = int(sys.argv[1])
    at_a_time = 1
else:
    n = int(sys.argv[1])
    at_a_time = int(sys.argv[2])

numruns = 0

counts = []

def rndwd(n):
    if at_a_time == 1:
        return np.random.binomial(n,0.5, 1)
    else:
        return np.random.binomial(n,0.5, at_a_time)

def update_hist(args):
    counts.extend(rndwd(n))
    plt.clf()

    plt.figtext(.2, .8, str(len(counts)), color='black', 
        bbox=dict(facecolor='none', edgecolor='black', boxstyle='round,pad=1', fc='white'))

    plt.hist(counts, bins=n, range=(0,n), rwidth=1, normed=True)

animation = animation.FuncAnimation(fig, update_hist, 100000)
plt.show()

