0
#include <random>
#include <iostream>
using namespace std;

vector<double> res;

int main()
{
    srand(time(NULL));
    std::random_device randomDevice;
    std::mt19937 generator(randomDevice());
    std::uniform_real_distribution<double> dist01(0,1);

    int n = 100;
    for (int i=1;i<=n;i++) res.push_back(dist01(generator));
    for (int i=1;i<=n;i++) {
            cout << res[i] << " ";
            if (i%10==0) cout << "\n";
    }
}

所以我有上面的程序。但问题是每次我运行时,结果都是一样的,即使我已经设置了srand(time(NULL))

我错过了什么?如何使输出随机?

谢谢

4

0 回答 0