Not necessarily, we can just pick one that acts as a middle ground and say “if in doubt, use this”.
The difference between the types of PRNG are their data ranges, the cheapness of implementations and the quality of the randomness they produce.
A linear congruential generator gives pretty poor quality random numbers, but LCGs usually suffice for basic games and they’re really cheap.
A mersenne twister gives really good quality random numbers, but they require a lot of memory in exchange for that quality.
rand
has no guarantees as to its quality. It could be something better than a mersenne twister, it could be something worse than an LCG. Technically it could probably just return 4;
every time.
The code could look something like this:
const int seed = Pokitto::getRandomSeed<int>();
srand(seed);
Or this:
using SeedType = typename std::knuth_b::result_type;
const SeedType seed = Pokitto::getRandomSeed<SeedType>();
std::knuth_b engine = std::knuth_b(seed);
Or if we went a step further:
std::knuth_b engine = Pokitto::createRandomlySeededEngine<std::knuth_b>();
Where createRandomlySeededEngine
is implemented as something like:
template< typename EngineType >
EngineType createRandomlySeededEngine(void)
{
using SeedType = typename EngineType::result_type;
return EngineType(getRandomSeed<SeedType>());
}
I think for now the best thing to do is just pool ideas and make a wishlist of features.