我使用boost ::随机生成遵循均匀分布的随机变量。
boost::mt19937 gen(2014/*time(NULL)*/);
boost::uniform_real<> dist(0, 1);
boost::variate_generator<boost::mt19937&, boost::uniform_real<> > random(gen, dist);
与此变量,我均匀地选择在每个不同的实验不同的起始图形节点。
for(unsigned int i=0; i < numQueries; i++)
{
//source node id
sourceID = (unsigned int) ( 1 + random() * G.getNumNodes());
//...
}
但我需要一种方法来在我的程序的每个不同的运行不同的初始化种子,正如我在每一个不同的运行得到首发节点的相同顺序了。
您可以使用的boost :: random_device使用机器的随机池(这是不确定的)种子的确定性发生器。
#include <boost/random.hpp>
#include <boost/random/random_device.hpp>
#include <iostream>
unsigned int numQueries = 10;
int main(int argc, char* argv[])
{
boost::random_device dev;
boost::mt19937 gen(dev);
//boost::mt19937 gen(2014/*time(NULL)*/);
boost::uniform_real<> dist(0, 1);
boost::variate_generator<boost::mt19937&, boost::uniform_real<> > random(gen, dist);
for(unsigned int i=0; i < numQueries; i++)
{
// I don't have G, so I'm just going to print out the double
//sourceID = (unsigned int) ( 1 + random() * G.getNumNodes());
double sourceID = (random());
std::cout << sourceID << std::endl;
}
return 0;
}