Changing the parameters of a random number generator

I use boost::randomto generate random velocity values, and I want to change the average and variance in response to user input.

I am using the following:

typedef boost::mt19937 RNG;
static RNG rng();

typedef boost::normal_distribution<double> DIST;
DIST dist_east(vel_e, sigma);
DIST dist_north(vel_n, sigma);

boost::variate_generator<RNG, DIST> east(rng, dist_east);
boost::variate_generator<RNG, DIST> north(rng, dist_north);

velocity.east = east();
velocity.north = north();

My problem is that I get only one value returned from two variable generators each time it is called. The values ​​change when vel_e, vel_n or sigma changes, but otherwise I get the same value.

I tried to make dist_east, dist_north, east and north objects static, but I cannot change the parameters after building.

Is there any way to achieve what I want?

+3
source share
3 answers

-, - 1 0. , , .

y = mean + sigma * x
+4

U - 0 1,

V = mu + sigma * U

mu sigma².

, , , ( 0, stdev 1) .

+3

, , , . , , , , , . , .

, , .

Edit: ( , )

generateNormalDistribution(mean, deviation)  
    X = boost::uniformGeneratorBetween0and1  
    Y = boost::uniformGeneratorBetween0and1  
    return [sqrt(-2*ln(X)) * cos(2*pi*Y)]*deviation + mean
0

All Articles