C++ get random number via uniform_int_distribution in template
#pragma once #include <iostream> #include <random> using namespace std; static random_device rd; static mt19937_64 mt(rd()); template<typename T> T getRandom(T min, T max) { srand(time(NULL)); uniform_int_distribution<T> uid(min, max); return uid(mt); } void printRandom(int len) { for (int i = 0; i < len; i++) { cout << i << "," << getRandom<uint64_t>(0, UINT64_MAX) << endl; } } int main() { printRandom(100); }