Questions tagged [boost-random]

The Boost Random Number Library (Boost.Random for short) provides a variety of generators and distributions to produce random numbers having useful properties, such as uniform distribution. Boost are free peer-reviewed portable C++ source libraries that work well with the C++ Standard Library.

40 questions
11
votes
4 answers

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

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…
Greg Rogers
  • 33,366
  • 15
  • 63
  • 93
8
votes
1 answer

Priming the Mersenne twister PRNG

There seems to be some mythology around the use of mt19937, specifically that once seeded 'some' number of bits produced by the generator should be ignored so as to have only as near as is possible to pseudo randomness. Examples of code I've seen…
user1781730
8
votes
3 answers

Random numbers from Beta distribution, C++

I've written a simulation in C++ that generates (1,000,000)^2 numbers from a specific probability distribution and then does something with them. So far I've used Exponential, Normal, Gamma, Uniform and Poisson distributions. Here is the code for…
jaff
  • 83
  • 1
  • 4
6
votes
1 answer

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

I would like to initialize boost::random::discrete_distribution with an std::vector. 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,…
hyperknot
  • 12,019
  • 22
  • 87
  • 143
6
votes
2 answers

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

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…
Eamon Nerbonne
  • 43,645
  • 18
  • 92
  • 161
6
votes
2 answers

Is boost::uuids::random_generator thread safe?

Consider this function compiling with g++ -std=c++11 (GCC 4.7.2): boost::uuids::uuid getID() { static boost::uuids::random_generator generator; return generator(); } Is it safe to call getID from multiple threads? As it is mentioned here…
Vahagn
  • 4,190
  • 8
  • 33
  • 67
5
votes
2 answers

How to generate random 64 bit ints with boost random

I'm trying to generate a random 64bit unsigned integer using boost random, but I'm getting an assertion failure with uniform_int. struct timeval tv; boost::mt19937 randGen(tval.tv_usec); boost::uniform_int<> uInt64Dist(0,…
hookenz
  • 30,814
  • 37
  • 149
  • 251
5
votes
3 answers

Crossplatform reproducible number generator

I need a "random" number generator, which produces the same result for a given seed on Windows, Mac, Linux, iOS and Android. Now I tried std::rand and boost::random_int_generator with boost::mt19937 but sadly the result is different between Windows…
abergmeier
  • 11,287
  • 10
  • 49
  • 88
4
votes
2 answers

Thread-safety of boost RNG

I have a loop which should be nicely parallelized by insering one openmp pragma: boost::normal_distribution ddist(0, pow(retention, i - 1)); boost::variate_generator dgen(rng, ddist); // Diamond …
Maciej Piechotka
  • 6,571
  • 4
  • 35
  • 57
4
votes
3 answers

Using boost::random to select from an std::list where elements are being removed

See this related question on more generic use of the Boost Random library. My questions involves selecting a random element from an std::list, doing some operation, which could potentally include removing the element from the list, and then choosing…
mindless.panda
  • 3,806
  • 3
  • 32
  • 56
4
votes
1 answer

How to generate a secure session id

for a C++ Web-Server I have to generate session id's. I thought of using some kind of random number and hash that with the initial IP address of the session and maybe a timestamp. Will this yield a reasonable unguessable ID? What would be a good…
Torsten Robitzki
  • 2,939
  • 18
  • 34
3
votes
1 answer

How to initialize boost::random::discrete_distribution using double[];

I would like to initialize boost::random::discrete_distribution with a double[] like this: boost::random::discrete_distribution<>* distribution(double* _distr) { return new boost::random::discrete_distribution<>(_distr); } I know I can use…
Emsi
  • 51
  • 5
3
votes
1 answer

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

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…
911
  • 808
  • 7
  • 16
3
votes
1 answer

How to reuse and reinitialize c++ discrete_distribution in class?

I am writing a discrete distribution random number generator in a c++ class. The requirements are: I don't want to create a discrete_distribution object each time I use it. I know distribution object is lightweight, but my weight array is so long…
3
votes
6 answers

Encapsulating boost::random for ease of usage to replace rand()

for my program I need pseudo random integers with different ranges. Until now I used the rand() function but it has it's limitations. I found the boost::random library to be a much better replacement but I didn't want to create random generators all…
zitroneneis
  • 967
  • 1
  • 10
  • 21
1
2 3