fast random number generator

Apr 20, 2012 at 10:41am
After a google search, it seems like this question has been asked to death, yet no clear answer was given; instead, lots of people dodged the question by saying "why do you need it so fast?" or "you need to call srand only once." I understand if it's too complex to answer in one reply, but I doubt it.

All that said, I'll ask again: how do you generate numbers faster than just using time(0) as the seed value of srand?
Apr 20, 2012 at 10:52am
Why do you need it so fast?

You need to call srand only once.

Couldn't resist.

There's a bunch of random number algorithms you could try implementing yourself although, to be honest, I've got no idea which are faster than others.

You could write a few and test them out compared to rand(), though.

http://en.wikipedia.org/wiki/Random_number_generation
Last edited on Apr 20, 2012 at 11:15am
Apr 20, 2012 at 11:08am
The seed value doesn't affect the time it takes to generate random numbers. The implementation of std::rand() can differ between different systems so it could be fast or slow, good or bad.

I think Multiply-with-carry is fast. http://en.wikipedia.org/wiki/Multiply-with-carry

C++11 added a few random generators to C++. You could test one of these.
Topic archived. No new replies allowed.