[reddit] random_numbers_generation_in_c
Random numbers generation in C++
Random numbers generation in C++
#include <stdint.h> #include <algorithm> #include <functional> #include <iostream> #include <random> #include <vector> using namespace std; int main() { random_device rd; vector<uint32_t> v(mt19937::state_size); generate(v.begin(), v.end(), ref(rd)); seed_seq seed(v.begin(), v.end()); mt19937 mt(seed); vector<uint32_t> v64(mt19937_64::state_size * 2); // because 2 * 32 == 64 generate(v64.begin(), v64.end(), ref(rd)); seed_seq seed64(v64.begin(), v64.end()); mt19937_64 mt64(seed64); cout << mt() << endl; cout << mt64() << endl; }
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.