hyperknot
hyperknot

Reputation: 13966

standard multivariate normal random vector using Boost::random

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?

Upvotes: 2

Views: 1249

Answers (1)

Peter K.
Peter K.

Reputation: 8108

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.

Upvotes: 3

Related Questions