vc++ get random via random_device,mt19937
#include <ctime> #include <iostream> #include <random> using namespace std; static random_device rd; static mt19937 mt{ rd() }; template<typename T> void getRandomArray(T* arr, int len, T min, T max) { uniform_int_distribution<T> uid(min, max); for (int i = 0; i < len; i++) { arr[i] = uid(mt); } } template<typename T> void printArray(T* arr, int len) { for (int i = 0; i < len; i++) { cout << i << "," << arr[i] <<"\t"; } cout<<endl<<endl << "Finished in " << __FUNCTION__ << endl; } void arrayDemoT(int len); int main(int args,char**argv) { int len = atoi(argv[1]); arrayDemoT(len); } void arrayDemoT(int len) { uint32_t* arr = new uint32_t[len]; getRandomArray<uint32_t>(arr, len, 0, UINT32_MAX); printArray<uint32_t>(arr, len); delete[]arr; } template<typename T> void getRandomArray(T* arr, int len, T min, T max) { uniform_int_distribution<T> uid(min, max); for (int i = 0; i < len; i++) { arr[i] = uid(mt); } }