This is the mail archive of the gsl-discuss@sourceware.org mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: circular random number distribution


> ,----
>
> | 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]