boost random in 2 dimensions

165 Views Asked by At

I am trying to use a boost random generator to make random points uniformly distributed over a plane surface. I have the following link for doing it in a single dimension:

Here they use boost::uniform_int<> to generate numbers as int in a single dimension.

But in my case I wish to generate numbers as float in two dimensions over a plane.

Is there any distribution type available to use it in two dimensions? (I have seen boost::uniform_on_sphere, but it is for spherical surfaces.)

2

There are 2 best solutions below

6
filmor On

Use the uniform_01 distribution and generate two random numbers, giving you the x and y coordinates. Scale accordingly :)

3
Audrius Meškauskas On

If x follows uniform distribution 0 to a and y follows uniform distribution 0 to b then points (x, y) are uniformly distributed over the rectangle (0,0)-(a,b) without any special approaches. Just generate the two random numbers rather than one.

These would be required to distribute them differently, at the edge of the circle, for instance (as you talk about the sphere).