C++ 使用C+生成泊松到达日期+;促进
我正在做一个运输网络的模拟程序。我想模拟一个乘客到达一个有毒物质分布为λ的公交车站 事实上,在我对该计划的概念中,我需要两个到达日期列表:第一个被视为乘客的预期到达日期,第二个被视为乘客的实际有效到达日期 为了生成到达时间,我使用boost使用了以下代码:C++ 使用C+生成泊松到达日期+;促进,c++,boost,poisson,C++,Boost,Poisson,我正在做一个运输网络的模拟程序。我想模拟一个乘客到达一个有毒物质分布为λ的公交车站 事实上,在我对该计划的概念中,我需要两个到达日期列表:第一个被视为乘客的预期到达日期,第二个被视为乘客的实际有效到达日期 为了生成到达时间,我使用boost使用了以下代码: <blink> double lambda(Lambda1); //mean of Poisson distr boost::mt19937 rnd_gen; //Mersenne Twister generat
<blink>
double lambda(Lambda1); //mean of Poisson distr
boost::mt19937 rnd_gen; //Mersenne Twister generator
typedef boost::variate_generator<
boost::mt19937, boost::poisson_distribution<>
> rnd_poisson_t;
rnd_poisson_t rnd_poisson( rnd_gen,
boost::poisson_distribution<>( lambda ) );
rnd_poisson = rnd_poisson_t( rnd_gen,
boost::poisson_distribution<>( lambda ));
for(int i = 0; i <size;i++)
{
value=rnd_poisson();
tab[i]= rnd_poisson();
i++;
}
</blink>
双λ(λ1)//泊松分布均值
增压:mt19937 rnd_gen//梅森捻线发生器
typedef boost::变量_生成器
boost::mt19937,boost::泊松分布
>rnd_poisson_t;
rnd_poisson_t rnd_poisson(rnd_gen,
boost::泊松分布(lambda);
rnd_poisson=rnd_poisson_t(rnd_gen,
boost::泊松分布(lambda);
对于(int i=0;i每当您使用随机生成器时,都会使用当前时间对其重新设定种子。这将在大多数时间产生不同的序列。正如您所发现的:
rnd_gen(static_cast<unsigned int>(std::time(0)));
rnd_gen(静态_cast(std::time(0));
在创建列表之前,每次重新给随机生成器(rnd_gen
)播种如何?这不会导致它给出不同的序列吗?谢谢你的提示。我实际上在声明中添加了这行代码:boost::mt19937 rnd_gen(static_cast(std::time(0)));而且每次调用此函数时,它都能正常工作。再次感谢。为完整起见,我将您的结论作为答案发布。