Write some other Monte Carlo generators, but this time generate accord to some simple integratable function say X2 or sin(X). A little bit of theory here may be of use:-
So, for example, to generate a point between 0. and 1. according to X2 use , where r is a random number between 0. and 1.Starting with a random number r in the range we seek a method that will generate x in the range a to b according to f(x). This requires that the probability of a value in the range x to be generated from a random number in the range r to must be proportional to
But the probability that the random number will lie in the range r to is just . So
Taking the limit and integrating gives
and imposing the boundary conditions x=a when r=0and x=b when r=1 leads to
Write a program to generate points randomly inside a sphere.