circular random number distribution

Jochen Küpper jochen@fhi-berlin.mpg.de
Fri Aug 5 21:59:00 GMT 2005


I need to calculate 2d random numbers uniformly distributed over a
circle (uncorrelated).

The closest match in GSL I can find is gsl_ran_dir_2d, but when using
that with an additional random number for the length, it will
obviously not yield a uniform distribution, but a density peaked at
the center of the circle.

Currently I am calculating a uniform distribution over a square and
reject the values outside the circle:
,----
| 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?

Greetings,
Jochen
-- 
Einigkeit und Recht und Freiheit                http://www.Jochen-Kuepper.de
    Liberté, Égalité, Fraternité                GnuPG key: CC1B0B4D
        (Part 3 you find in my messages before fall 2003.)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gsl-discuss/attachments/20050805/1573a8e3/attachment.sig>


More information about the Gsl-discuss mailing list