|
Boost Users : |
From: Deng Kun (dengkun1977_at_[hidden])
Date: 2004-11-28 16:14:56
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 <stdlib.h>
#include <boost/random.hpp>
#include <boost/dynamic_bitset.hpp>
class RandomBitset {
public:
typedef boost::mt19937 EngineType;
typedef boost::bernoulli_distribution<> DistType;
typedef boost::variate_generator<EngineType, DistType> 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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net