circular random number distribution
Daniel Franke
daniel.franke@imbs.uni-luebeck.de
Fri Aug 5 22:33:00 GMT 2005
> ,----
>
> | do {
> | x = gsl_ran_flat(rng, -1, 1);
> | y = gsl_ran_flat(rng, -1, 1);
> | } while(sqrt(x*x + y*y) > 1.);
>
> `----
>
> Is there a better approach to this? Is there a function in GSL I
> overlooked?
Jochen,
try to sample random polar coordinates (r, phi) where r from [0, r_max] and
phi from [-M_PI, M_PI]. Transform these polar coordinates to cartesian (x,y)
afterwards.
I don't know whether these (x,y) have a true uniform distribution over a disk
of radius r_max, but you get valid pairs each time you draw.
Regards
Daniel
More information about the Gsl-discuss
mailing list