2

I would like to generate random points on a 2D surface, distributed around a x0, y0 coordinate.

I understand that what I need to generate is called "standard multivariate normal random vector", but I don't know how to do it in C++, for example using the Boost::random library.

I know there is an algorith for generating this, called Box–Muller transform but I would think that this must have already been implemented properly in Boost.

Is there any simple way to generate multivariate normal distribution, using Boost::random?

hyperknot
  • 13,454
  • 24
  • 98
  • 153

1 Answers1

3

It seems to be:

// deterministic Box-Muller method, uses trigonometric functions
template<class RealType = double>
class normal_distribution
{

But Box-Muller isn't 2D. All you really have to do to get the 2D version is to take the two random numbers generated and add them to the x0, y0 coordinates.

Peter K.
  • 8,028
  • 4
  • 48
  • 73
  • 4
    Indeed, an n-dimensional normal distribution is normal in each of its components. Write out the density function, you see that it factors as a product if 1D density functions. Also, use C++0x's `` if you have it ;-) – Kerrek SB Jul 12 '11 at 16:42