Use of Uniform Random Number Generator to Access Weighted Probability Distribution
The impetus for this document is an electron diffraction animation. I wanted to show the buildup of the wave-directed electrons in the far field of a slitted screen upon which electrons are incident one-by-one. After many electrons have passed, the envelope of the histogram of number of electrons Vs far-field angle will be a product of two sinc functions. This is the weighted probability distribution of the title.
The method that I came up with is to discretize and compress the algebraic distribution. Each of the discrete expanded blocks in the new frequency distribution will have the same area but a width proportional to the value of the probability that that block represents. This way, when we choose uniform random variables on the entire numerical domain of the blocks, we will be choosing fewer values where the original probability was low.
Let the original distribution be written as:
(1)
where s is the width at 1/e of the distribution and dP/dx is the probability that x will be in the interval dx.
We will remap the numbers describing the distribution such that the range of numbers corresponding to P(x) is proportional to the value of P(x). i.e.
dN(x)/dx=NT dP(x)/dx and make NT>>1/(dP/dx)Minimum
.
i.e.
where xn varies in units of (xmax-xmin)/NT. Having computed ki, and saved it to an array then we use the computer’s uniformly distributed random number generator to select a number g from the range 0 to kmax. Then we use the following algorithm to compute the i value to which g corresponds:
int i=0;
do
{
i++;
}
while(k[i]<g);
return i;
The final result appears as shown in Figure 1:
Figure 1: Both the original Gaussian probability
distribution and the weighted profile (really a frequency distribution)
generated by the compression technique described above.