If I evaluate the following code, I get what I expect - roughly half 1's and a quarter 0's and 2's.
n = 2; p = 0.5;
item := RandomVariate[BinomialDistribution[n, p]];
Table[item, {1000}] // Tally
However, if I then evaluate the following bit of code, the 0's 1's and 2's are evenly distributed. I can't figure out why. Anyone see my error?
k = 0; on = False;M = 1000;
b = Probability[s == Floor[n p],
s \[Distributed] BinomialDistribution[n, p]];
f = Association @@ (Map[# -> 0 &, Range[0, n]]); {{{Button[
"Start/Stop", on = Not[on]]}, {Button["Reset",
f = Association @@ (Map[# -> 0 &, Range[0, n]]); k = 0]}},
Dynamic[If[on && k < M, f[item] += 1; k += 1;
BarChart[f, ChartLabels -> Range[0, n],
PlotRange -> {-0.1 M, 1.2 M b}],
BarChart[f, ChartLabels -> Range[0, n],
PlotRange -> {-0.1 M, 1.2 M b}]]]}
Attachments: