Getting big random numbers in C/C++

You can easily do this with std::uniform_int_distribution<unsigned long long>.

Simple example code (taken from here, modified to use unsigned long long):

#include <random>
#include <iostream>

int main()
{
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<unsigned long long> dis(lowerBorder, upperBorder);

    for (int n=0; n<10; ++n)
        std::cout << dis(gen) << ' ';
    std::cout << '\n';
}

Note that the seeding of the mersenne twister as done here for demo purposes is not perfect, for example see here.

Leave a Comment