From: Marcus Bannerman (m.bannerman_at_[hidden])
Date: 2007-11-12 03:43:52
I have adapted the current normal_distribution from the polar form to
the outward Cartesian form. See here
listing the benefits of the Cartesian form for the distribution of
numbers. This also eliminates trigonometric function calls, however,
it does reject pairs of random numbers. Most websites (wolfram,
wikipedia) state that the inward Cartesian form is faster but this is
generator speed dependent.
I've found with my tests
(mt19937, double datatype, gcc (GCC) 4.1.3 20070929 (prerelease)
(Ubuntu 4.1.2-16ubuntu2), -O2)
its about 1.5x slower than the polar form. Although with faster
generators I expect it to outperform the polar version.
I think this is an improvement on the current normal_distribution.hpp
in time critical situations (if a fast generator is used) and it gives
a better distribution of numbers, (points rather than bands of
inaccessible numbers). I have also found that this version doesn't
produce the "may be used uninitialised" warning when compiling with
optimisations that I get when I use the original.
Please let me know if you think of any other improvements or spot any
errors. I will use this in my code however I would like to give
I'm not sure what to do with the copyright at the top of the file and
I'm not sure if this is the correct way to submit this for review.
Apologies in advance if I have made a mistake.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk