boost random number library, use same random number generator for different variate generators

前端 未结 1 1453
天命终不由人
天命终不由人 2021-02-04 11:32

It seems that one can use the following code to produce random numbers from a particular Normal distribution:

float mean = 0, variance = 1;
boost::mt19937 randge         


        
1条回答
  •  情书的邮戳
    2021-02-04 12:01

    Your hypothesis is correct. You want both variate_generator instances to use the same random number generator instance. So use a reference to mt19937 as your template parameter.

    variate_generator > nD(randgen, noise1);
    variate_generator > nC(randgen, noise2);
    

    Obviously you'll have to ensure randgen does not go out of scope before nD and nC do.

    0 讨论(0)
提交回复
热议问题