|
Boost : |
From: Mario Ruetti (mruetti_at_[hidden])
Date: 2004-04-08 09:06:04
Hi,
to fulfill Jens Maurers wg21-proposal (C++ TR proposal) for random number
facilities,
a "Pseudo-random number engine" has to implement a 'seed()' method as
written in
chapter IV, "Proposed Text". Some of the boost generators don't implement
this
method, these are
* linear_feedback_shift
* additive_combine
* inversive_congruential
* discard_block
* shuffle_output
I added the missing method as seen in the diff quotes below.
To test the changes I used the post-condition which has to be fulfilled
after seed()
has been called, namely u.seed() == X() (same state as after default
constructor called)
//
test's
//****************************************************************************
ecuyer1988 ec, ec1;
rngTest.register_rng<ecuyer1988>("Ecuyer 1988");
ec.seed();
if (ec == ec1)
std::cout << "* additive_combine -> OK \n";
else
std::cout << "- additive_combine \n";
taus88 taus;
rngTest.register_rng<taus88>("Tausworthe 88");
taus.seed();
taus88 taus1;
if (taus == taus1)
std::cout << "* linear_feedback -> OK \n";
else
std::cout << "- linear_feedback \n";
boost::hellekalek1995 helle, helle1;
rngTest.register_rng<boost::hellekalek1995>("Hellekalek 1995");
helle.seed();
if (helle == helle1)
std::cout << "* inverse_cong -> OK \n";
else
std::cout << "- inverse_cong \n";
boost::ranlux64_3_01 ranlux, ranlux1;
rngTest.register_rng<boost::ranlux64_3_01>("RanLux 64 Base");
ranlux.seed();
if (ranlux == ranlux1)
std::cout << "* discard_block -> OK \n";
else
std::cout << "- discard_block \n";
boost::kreutzer1986 kreutz, kreutz1;
rngTest.register_rng<boost::kreutzer1986>("Kreutzers Generator");
kreutz.seed();
if (kreutz == kreutz1)
std::cout << "* shuffle_output -> OK \n";
else
std::cout << "- shuffle_output
\n";
//****************************************************************************
output:
* additive_combine -> OK
* linear_feedback -> OK
* inverse_cong -> OK
* discard_block -> OK
* shuffle_output -> OK
Bye Mario Ruetti
Index: linear_feedback_shift.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/random/linear_feedback_shift.hpp,v
retrieving revision 1.7
diff -r1.7 linear_feedback_shift.hpp
83c83
< void seed(UIntType s0) { assert(s0 >= (1 << (w-k))); value = s0; }
--- > void seed(UIntType s0 = 341) { assert(s0 >= (1 << (w-k))); value = s0; } Index: additive_combine.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/random/additive_combine.hpp,v retrieving revision 1.5 diff -r1.5 additive_combine.hpp 62a63,68 > void seed() > { > _mlcg1.seed(); > _mlcg2.seed(); > } > Index: inversive_congruential.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/random/inversive_congruential.hpp,v retrieving revision 1.6 diff -r1.6 inversive_congruential.hpp 63c63 < void seed(IntType y0) { value = y0; if(b == 0) assert(y0 > 0); } --- > void seed(IntType y0 = 1) { value = y0; if(b == 0) assert(y0 > 0); } Index: discard_block.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/random/discard_block.hpp,v retrieving revision 1.7 diff -r1.7 discard_block.hpp 52a53 > void seed() { _rng.seed(); _n = 0; } Index: shuffle_output.hpp =================================================================== RCS file: /cvsroot/boost/boost/boost/random/shuffle_output.hpp,v retrieving revision 1.6 diff -r1.6 shuffle_output.hpp 65a66 > void seed() { _rng.seed(); init(); } -- NEU : GMX Internet.FreeDSL Ab sofort DSL-Tarif ohne Grundgebühr: http://www.gmx.net/info
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk