Idealized Galton Board

Manipulate[
If[j>k,j=k];
μ=i/2;σ=Sqrt[i]/2;y=k*PDF[NormalDistribution[μ,σ],x];Histogram[Take[data[[i/25,1]],{1,j}],{.5,i+.5,1},AxesOrigin->{0,0},Epilog->First@Plot[y,{x,0,i},PlotStyle->Red],PlotRange->{{0,i+.5},{0,Max[BinCounts[Take[data[[i/25,1]],{1,k}]]]}},ImagePadding->20,ImageSize->{500,300}],
{{k,100,"number of balls"},{100,500,1000,5000}},
{{i,25,"number of slots"},{25,50,75}},
{{j,0,"fallen balls"},0,k,1,Appearance->"Labeled",ImageSize->Tiny},
Button[Style["new simulation","Label",Small],{data=Table[RandomInteger[BinomialDistribution[i,0.5],{1,5000}],{i,25,75,25}],j=0},ImageSize->Small],
Initialization:>{data=Table[RandomInteger[BinomialDistribution[i,0.5],{1,5000}],{i,25,75,25}];},
TrackedSymbols->{i,j,k}]

A Galton board is a vertically oriented board with evenly spaced pegs on which a classic statistical experiment can be performed by dropping balls from the top center of the board. The balls bounce to the left or the right as they hit pegs on their way down the board, coming to rest in slots at the bottom, possibly displaced from the center. On an idealized Galton board, each ball bounces left or right when it hits a peg with probability 1/2. The piles of balls that accumulate in the slots give rise to a binomial distribution. This Demonstration shows how the fallen balls accumulate and gives the number of balls in each slot. When the numbers of balls and slots are sufficiently large, you can see that the shape of the distribution of the fallen balls is close to a bell curve.

Contributed by: Bernard Vuilleumier