C ++中随机数生成器的重复值

时间:2018-10-08 18:40:20

标签: c++ random

我正在运行以下C ++程序。

    #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';
      }

但是,如果多次运行,我会得到相同的输出。

这是在Windows计算机上。实际上,它可以在Mac和Ubuntu上正常工作。

欢迎提出任何建议。

谢谢!

0 个答案:

没有答案