I am currently developing a distributed application where many clients
need to generate unique 64-bit random numbers which will be used as
keys. I am having problems getting boost to do this. For my first
attempt, I tried something like the following:
boost::mt19937 RandomNumberGenerator::s_algorithm;
boost::uniform_int<unsigned long long> RandomNumberGenerator::s_range(
std::numeric_limits<unsigned long long>::min(), std::numeric_limits<unsigned long long>::max());
boost::variate_generator<boost::mt19937&, boost::uniform_int<unsigned long long> >
RandomNumberGenerator::s_rng(RandomNumberGenerator::s_algorithm, RandomNumberGenerator::s_range);
I had two issues though:
1. Is this really giving me random 64 bit numbers, or is it just generating 32-bit numbers and then doing bit expansion?
2. The values always started with the same number.
Trying to find a fix for #2, I though of using a hashed GUID as a
seed. The problem is I noticed the seed value takes a 32 bit int,
which essentially means a 1/2^32 chance of the first value colliding
even if chosen completely randomly, which is unacceptable for my
application.
I am back where I started. Is there any clean way to use boost to
generate random 64-bit intergers, when the same application is going to
be run across multiple computers?