boost-random

Thread-safety of boost RNG

瘦欲@ 提交于 2020-01-11 05:58:07
问题 I have a loop which should be nicely parallelized by insering one openmp pragma: boost::normal_distribution<double> ddist(0, pow(retention, i - 1)); boost::variate_generator<gen &, BOOST_TYPEOF(ddist)> dgen(rng, ddist); // Diamond const std::uint_fast32_t dno = 1 << i - 1; // #pragma omp parallel for for (std::uint_fast32_t x = 0; x < dno; x++) for (std::uint_fast32_t y = 0; y < dno; y++) { const std::uint_fast32_t diff = size/dno; const std::uint_fast32_t x1 = x*diff, x2 = (x + 1)*diff;

Using boost::random as the RNG for std::random_shuffle

时光怂恿深爱的人放手 提交于 2019-12-18 11:59:32
问题 I have a program that uses the mt19937 random number generator from boost::random. I need to do a random_shuffle and want the random numbers generated for this to be from this shared state so that they can be deterministic with respect to the mersenne twister's previously generated numbers. I tried something like this: void foo(std::vector<unsigned> &vec, boost::mt19937 &state) { struct bar { boost::mt19937 &_state; unsigned operator()(unsigned i) { boost::uniform_int<> rng(0, i - 1); return

Boost random::discrete_distribution How to change weights once constructed?

南楼画角 提交于 2019-12-10 18:57:27
问题 Ok, it is possible to give weights/probabilities in boost::random::discrete_distribution. e.g. double probabilities[] = { 0.5, 0.1, 0.1, 0.1, 0.1, 0.1 }; boost::random::discrete_distribution<> dist (probabilities); Question: Once the object dist is constructed (1)How to change one of the weights e.g. 0.5 to 0.3? (2) How to reassign all the weights at once? 回答1: Create a new distribution object and use that instead. 来源: https://stackoverflow.com/questions/8925545/boost-randomdiscrete

Boost Mersenne Twister: how to seed with more than one value?

浪子不回头ぞ 提交于 2019-12-07 02:21:39
问题 I'm using the boost mt19937 implementation for a simulation. The simulation needs to be reproducible, and that means storing and potentially reusing the RNG seeds later. I'm using the windows crypto api to generate the seed values because I need an external source for the seeds and not because of any particular guarantees of randomness. The output of any simulation run will have a note including the RNG seed - so the seed needs to be reasonably short . On the other hand, as part of the

Boost Mersenne Twister: how to seed with more than one value?

不打扰是莪最后的温柔 提交于 2019-12-05 06:45:40
I'm using the boost mt19937 implementation for a simulation. The simulation needs to be reproducible, and that means storing and potentially reusing the RNG seeds later. I'm using the windows crypto api to generate the seed values because I need an external source for the seeds and not because of any particular guarantees of randomness. The output of any simulation run will have a note including the RNG seed - so the seed needs to be reasonably short . On the other hand, as part of the analysis of the simulation, I'll be comparing several runs - but to be sure that these runs are actually

Initializing a member class of an object using a non-default constructor in C++

寵の児 提交于 2019-12-02 06:52:11
问题 I have a specific situation where I've got an object that I want to use the boost random number generators on, and it has lead to a greater question which I cannot seem to answer. Here is the example code of what I'm trying to produce. First, my header: Class MyObject { protected: double some variable; boost::random::mt19937 rgenerator; boost::uniform_real<double> dist_0_1; boost::variate_generator< boost::mt19937&, boost::uniform_real<double> > rand01 } Now what I want to do is: Class

Thread-safety of boost RNG

泪湿孤枕 提交于 2019-12-01 06:24:26
I have a loop which should be nicely parallelized by insering one openmp pragma: boost::normal_distribution<double> ddist(0, pow(retention, i - 1)); boost::variate_generator<gen &, BOOST_TYPEOF(ddist)> dgen(rng, ddist); // Diamond const std::uint_fast32_t dno = 1 << i - 1; // #pragma omp parallel for for (std::uint_fast32_t x = 0; x < dno; x++) for (std::uint_fast32_t y = 0; y < dno; y++) { const std::uint_fast32_t diff = size/dno; const std::uint_fast32_t x1 = x*diff, x2 = (x + 1)*diff; const std::uint_fast32_t y1 = y*diff, y2 = (y + 1)*diff; double avg = (arr[x1][y1] + arr[x1][y2] + arr[x2]

How to initialize boost::random::discrete_distribution using std::vector?

青春壹個敷衍的年華 提交于 2019-11-30 20:46:23
I would like to initialize boost::random::discrete_distribution with an std::vector<double> . My problem is that if I initialize it with an array, like in the official example: double probabilities[] = { 0.5, 0.1, 0.1, 0.1, 0.1, 0.1 }; boost::random::discrete_distribution<> dist(probabilities); then it works perfectly. However if I initialize it with a std::vector , then it behaves like if it has only one element with probability 1.0. Can you tell me what is the right way of initializing a boost::random::discrete_distribution<> with a vector? The class seems to have a constructor that takes an

How to initialize boost::random::discrete_distribution using std::vector?

风流意气都作罢 提交于 2019-11-30 04:38:57
问题 I would like to initialize boost::random::discrete_distribution with an std::vector<double> . My problem is that if I initialize it with an array, like in the official example: double probabilities[] = { 0.5, 0.1, 0.1, 0.1, 0.1, 0.1 }; boost::random::discrete_distribution<> dist(probabilities); then it works perfectly. However if I initialize it with a std::vector , then it behaves like if it has only one element with probability 1.0. Can you tell me what is the right way of initializing a

How do I use Boost Random [closed]

喜你入骨 提交于 2019-11-28 02:29:00
I need to generate random number with Boost Random. I tried to follow the general guide. I extracted the files of the library. So if I want to use the classes and objectj of the library how I should do? First I know including the library in the program. Then I have to compile the library and the program.cpp itself? (And both with the same compiler - I'm using g++). I am using a virtual box of ubuntu. It is first time that I am using library so I really don't know. the random number for my case must be double not just integer... So, you use a real number distribution. I'm not this kind of