I need to generate UUIDs for use as non-predictable / guessable session IDs.
This can easily be accomplished using boost's UUID library:
boost::uuids::uuid newUUID()
{
static boost::uuids::random_generator gen;
return gen();
}
The returned UUID can easily be converted to a string.
The above code is equivalent to:
boost::uuids::uuid newUUID()
{
static boost::uuids::basic_random_generator<boost::mt19937> gen;
return gen();
}
So we are using the Mersenne Twister 19937 pseudo random number generator. It looks like boost takes the task of seeding it properly serious.
However, I wonder if something important – security wise – is gained by using a non-deterministic RNG like boost::random_device instead, and also how it will impact the speed of UUID generation.
boost::uuids::uuid newUUID()
{
static boost::uuids::basic_random_generator<boost::random_device> gen;
return gen();
}
Advice from people with security insight is appreciated.