rand function

I want to use rand function that generate numbers form number bigger than RAND_MAX.
how can i do this?

thanks,

maya
Well, you could try writing your own random number generator.
Here's some info on wikipedia that could help:
http://en.wikipedia.org/wiki/Linear_congruential_generator
1
2
3
4
5
// assuming RAND_MAX is 2^32-1
u64 rand64()
{
  return ((u64)rand() << 32) | rand();
}



EDIT: actually... nevermind.

This would have poor distribution because you'd still have a period of 2^32.

Maybe you are better off writing your own.
Last edited on
Topic archived. No new replies allowed.