I am creating a treap, and I want to know, which random number generator is most suitable for generating priorities at insertion.
The data set is about 6000 items long.
I am modifying an existing template class(largely just declared methods without definitions) that was given to us. The predefined generator is std::default_random_engine which only generates pseudo-random numbers. I would like to know, if this generator is sufficient, and if not, what are the alternatives? The data will be read from a file all at once.
The random number generator is declared as:
std::default_random_engine* generator_;
It's only used when creating in a constructor of a wrapper class
TreapItem<K, T>(key, data, (*generator_)())
I'd like to have the least number of collisions possible. Is std::default_random_engine* generator_; enough, to achieve no collisions, or is there a need for some other generator?
EDIT: I'd prefer uniform distribution, or something that is close to it. Normal distribution might work too, however.
The pointer to the generator was in the given code, it didn't appear as a flaw at first glance.
This is a simple (but not exhaustive!) benchmark of the c++ random generators plus the ancient C rand function and a simple rot-xor generator.
There is a simple smoke test, taking a few bits from the middle of the number, but by no means crypto-proof.
I think they would all work well for a randomised binary search tree.
Results show surprising performance for the rather complex C++ defaults, only 3-5 times slower than a simple RNG. The best of the standard ones seems to be the subtract with carry versions ranlux_*. The old C rand() function, which I think contains a divide, is unsurprisingly the slowest.