Hello,

I am trying to generate a very large uniformly distributed pseudo-random number (around 15 digits, similar to Random.nextLong() in Java), the problem is that both rand() and random() only return int/long type (10 digits max).
Is there any way to generate pseudo-random number in long long int type?

Thank you.

Recommended Answers

All 2 Replies

Well if your rand() is say 16 bits, and you want 32 bits, you could do this unsigned long result = ((unsigned long)rand()) << 16 + (unsigned long)rand(); Just join 2 rands together.

For a much better random source, look at the boost library.
The standard rand() has no guarantees as to it's randomness (some implementations are horrible).

Hi vieestchien

There is also famous Mersenne Twister MTRand by Makoto Matsumoto.

krs,
tesu

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.