$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: nbecker_at_[hidden]
Date: 2001-04-02 10:30:14
Thanks for the ideas on the PN generator. Here is a new version that
I think is more in the spirit of boost:
#ifndef PNGen_H
#define PNGen_H
#include <boost/random.hpp>
template<class RNG>
class PNGen {
RNG& rng;
typename RNG::result_type cache;
int cnt;
public:
PNGen (RNG& _rng) :
rng (_rng),
cnt (0)
{}
void Refresh() {
cache = rng();
cnt = std::numeric_limits<typename RNG::result_type>::digits;
}
int Next() {
int bit = cache & 1;
cache >>= 1;
cnt--;
return bit;
}
int Bipolar() {
return (operator()() == 0) ? -1 : 1;
}
int Unipolar() {
return operator()();
}
int operator()() {
if (cnt == 0)
Refresh();
return Next();
}
};
#endif