can someone tell me how to seed the random library?
I am having some problem with the following code
the seed method won't compile on solaris but works fine on windows
especially in the "else" part
die->engine().seed((unsigned int)(s));
gives me some error.
#ifndef RANDOMBITSET_H
#define RANDOMBITSET_H
#include
#include
#include
class RandomBitset {
public:
typedef boost::mt19937 EngineType;
typedef boost::bernoulli_distribution<> DistType;
typedef boost::variate_generator DieType;
EngineType rng;
DistType dist;
DieType *die;
RandomBitset(double p=0.5): rng(), dist(p){
die= new DieType(rng, dist);
}
RandomBitset(const RandomBitset & r){
rng=r.rng;
dist=r.dist;
if (die!=NULL)
{
delete die;
}
die= new DieType(rng,dist);
}
virtual ~RandomBitset(){
delete die;
}
//force reseed
//input s<0 will use system time to reseed
//otherwise use s as seed
void seed(int s=-1){
if (s<0)
{
long rs=time(NULL);
srand(rs);
die->engine().seed((unsigned int) rand());
}else {
die->engine().seed((unsigned int)(s));
}
}
void randomBitset(boost::dynamic_bitset<> & bs);
};
#endif //RANDOMBITSET_H