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]

circular random number distribution


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.)

Attachment: pgp00000.pgp
Description: PGP signature


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