vendredi 17 avril 2015

Using Boost.Random to generate multiprecision integers from a seed

I am attempting to use the Boost multiprecision libraries for C++ to generate large random numbers. I have been unable to create a generator which is seeded by the time or another random number, so my generator produces the same numbers on every run. How do I seed the generator with a changing value to produce different values on each run? Here is the code which works but produces the same values on each run:



using namespace boost::multiprecision;
using namespace boost::random;

typedef independent_bits_engine<mt19937, 512, mpz_int> generator_type;
generator_type gen;

std::cout << gen() << "\n\n";


I have seeded the std mersenne twister before with success:



std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(1, 410);
std::cout << dis(gen);


but I am not sure how to seed the multiprecision mt. I get an error if I try to attach any arguments to the generator_type declaration.





Aucun commentaire:

Enregistrer un commentaire