泊松分布总是在每个 运行 处产生相同的实例

poisson distribution always produces same instances at each run

我正在尝试通过泊松分布为我的项目生成随机到达。代码部分:

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cmath>
#include <random>
#include <ctime>
int nextTime(double lambda,int timeslots,int PU_number);

int main()
{
    srand(time(0));
    //some code
    nextTime(4,time_slots,PU_number);
}
int nextTime(double lambda,int timeslots,int PU_number)
{
    int mat[PU_number][timeslots];
    std::default_random_engine generator;
    std::poisson_distribution<int> distribution(lambda);
    int number;
    int total=0;
    for(int i=0; i< PU_number;i++)
    {
        total=0;
        for(int j=0;j<timeslots;j++)
        {
            number = distribution(generator);
            total+=number;
            mat[i][j]=total;//another matrix, not relevant here
            cout<<number<<" ";
        }
        cout<<endl;
    }
    return 0;
}

以上代码总是产生相同的数字。这里有什么问题?

srand 种子 rand,不是你的 std::default_random_engine。要播种,请使用

std::default_random_engine generator(std::random_device{}());
                                     ^^^^^^^^^^^^^^^^^^^^^^
                                     e.g., any seed can go here