I am trying to generate random arrivals via poisson distribution for my project. The code part:
#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];
srand(time(0));
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;
}
Above code always produces same numbers. what is wrong here?
Aucun commentaire:
Enregistrer un commentaire