The Math.random() method of the java.lang.Math class generates random deviates with a uniform probability distribution, so that the probability of generating a number between x and x+dx, denoted by p(x)dx, is given by
p(x)dx = dx for 0<x<1,
0
otherwise
Now suppose we generate a uniform deviate x and then take some prescribed function of it, y(x). The probability distribution of y, denoted by p(y)dy, is determined by the funadamental transformation law of probabilities, which is simply
|p(y)dy| = |P(x)dx|
or
p(y) = p(x)|dx/dy|
ref.) p.214, Numerical Recipes In C, W.H.Press, B.P.Flannery, S.A.Teukolsky, and W.T.Vetterling, Cambirdge Univ. Press, Cambridge (New York, 1988)
From uniform deviates to linear deviates
Uniform:
p(x)dx = dx for 0<x<1
0
otherwise
Linear:
p(y)dy = ydy for 0<y<y0
0 otherwise
Hence,
ydy = dx, or y^2 / 2 = x or y = sqrt(2 * x).
Therefore, a Java program which simply converts
double x = Math.random();
to
double y = Math.sqrt( 2.0 * x);
will show the following result. Here the y axis denotes the frequency of occurence for 0 < x < 0.1, 0.1 < x < 0.2, etc in the first plot, and similarly for the y-distribution in the second plot.