lundi 8 octobre 2018

repeating values for Random number generator in c++

I am running the following C++ program.

    #include <iostream>
    #include <random>
    #include <string>
    #include <iterator>
    #include <algorithm>

       int main()
     {
        std::string in = "abcdefgh", out;
        std::sample(in.begin(), in.end(), std::back_inserter(out),
            5, std::mt19937{std::random_device{}()});
        std::cout << "five random letters out of " << in << " : " << out << 
             '\n';
      }

However, if it is run multiple times, I get the same output.

This is on a Windows machine. It actually works fine on a Mac and an Ubuntu.

Any suggestions welcome.

Thanks!




Aucun commentaire:

Enregistrer un commentaire