I need to generate random numbers, but from as wide a range as possible (64 bit at least). I don’t care if the distribution is perfect, so std::rand() would work, but it only returns an int. I understand that c++11 has some random number generating capability that can give any size number, but is very complex to use. Can someone post a simple example of how to use it as simply as possible to get the described functionality (64 bit or more random numbers) in as simple a way as possible (like std::rand())?
I need to generate random numbers, but from as wide a range as possible
Share
This is how to use the C++11 random number generation for this purpose (adjusted from http://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution):
Instead of
unsigned long long, you could usestd::uintmax_tfromcstdintto get the largest possible integer range (without using an actual big-integer library).