Nabeel_Afzal - 1 year ago 100

C++ Question

I want to generate very large random number in range of 0 - 2^64 using c++. I have used the rand() function but it is not generating very large number. Can any one help?

Answer Source

With c++11, using the standard random library of c++11, you can do this:

```
#include <iostream>
#include <random>
int main()
{
/* Seed */
std::random_device rd;
/* Random number generator */
std::default_random_engine generator(rd());
/* Distribution on which to apply the generator */
std::uniform_int_distribution<long long unsigned> distribution(0,0xFFFFFFFFFFFFFFFF);
for (int i = 0; i < 10; i++) {
std::cout << distribution(generator) << std::endl;
}
return 0;
}
```