In the vertical direction (the y axis), the probability is uniform. In other words, from top to bottom, the particle is equally likely to land anywhere.
In the horizontal direction (the x axis) , the probability is proportional to the square of a sine function. The relative probability can be written P(x) = sin2 x, where x runs from 0 to f×pi, f being the number of bands (equal to the number of fringes in the corresponding classical interference pattern). This probability function is valid if the slit-to-screen distance is much greater than the slit spacing, and the width of each slit is less than the wavelength. In the simulation, f is chosen to be 4.
You can set the number of particles to be detected, then augment this number by any additional number, and so on, or you may start over with a clean slate at any time. Suggestions: Start with a very small number (10 or fewer) to observe the seeming randomness of the individual detection events. Start over several times with the same small number to see that no two patterns are alike. Then add more particles, taking note of the smallest number that seems to reveal the fringe pattern. Then proceed to large numbers (thousands) to see how the individual detection events get transformed gradually into the classical interference pattern. (With very large numbers, you will see narrow bands within each fringe. This is an artifact attributable to finite pixel size on the screen.)
For a single band, the probability
P(x) vs. x is shown in the graph on the right. Randomly choosing the x
value where the particle is to land is equivalent to choosing a random
location in the area under this curve. Think of this area being divided
into a grid of tiny squares, each square being labeled by a number, starting
with zero at the lower left. Then choosing a random spot in the area under
the curve is equivalent to choosing a random number N between 0 and Nmax,
where Nmax is the total number of squares under the curve. This
random number N is equal to the number of squares to the left of the chosen
square, which is the integral of the function P(x) from zero to some value
q vertically under the chosen point. (All of this can be scaled so that
neither N nor Nmax need be an integer.)
This reasoning leads to the equation

with Nmax = pi/2. So the procedure is: (1) Randomly choose any vertical position. (2) Randomly choose any one of the four bands. (3) Within that band, choose a random number N between 0 and pi/2. Then solve the above equation for q (which cannot be done in closed form). The resulting value of q will be the horizontal position of the detection event within the chosen band.
Do the following n times, where n is the number of particles selected.
r is chosen randomly from the set 0, pi, 2 pi, 3 pi. This identifies in which band the particle lands.
q is the solution to the equationand N is a random number between 0 and pi/2. q identifies where within a band the particle lands.