This is the mail archive of the
gsl-discuss@sourceware.org
mailing list for the GSL project.
Re: circular random number distribution
- From: Daniel Franke <daniel dot franke at imbs dot uni-luebeck dot de>
- To: gsl-discuss at sources dot redhat dot com
- Date: Sat, 6 Aug 2005 00:32:53 +0200
- Subject: Re: circular random number distribution
- References: <m3k6j0qc47.fsf@doze.jochen-kuepper.de>
> ,----
>
> | 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