1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
// mersenne_twister_engine::seed example
#include <iostream>
#include <chrono>
#include <random>
int main ()
{
typedef std::chrono::high_resolution_clock myclock;
myclock::time_point beginning = myclock::now();
// obtain a seed from a user string:
std::string str;
std::cout << "Please, enter a seed: ";
std::getline(std::cin,str);
std::seed_seq seed1 (str.begin(),str.end());
// obtain a seed from the timer
myclock::duration d = myclock::now() - beginning;
unsigned seed2 = d.count();
std::mt19937 generator (seed1); // mt19937 is a standard mersenne_twister_engine
std::cout << "Your seed produced: " << generator() << std::endl;
generator.seed (seed2);
std::cout << "A time seed produced: " << generator() << std::endl;
return 0;
}
|