diff --git a/lemon/random.h b/lemon/random.h --- a/lemon/random.h +++ b/lemon/random.h @@ -575,6 +575,26 @@ return *this; } + /// \brief Seeding random sequence + /// + /// Seeding the random sequence. The current number type will be + /// converted to the architecture word type. + template + void seed(Number seed) { + _random_bits::Initializer::init(core, seed); + } + + /// \brief Seeding random sequence + /// + /// Seeding the random sequence. The given range should contain + /// any number type and the numbers will be converted to the + /// architecture word type. + template + void seed(Iterator begin, Iterator end) { + typedef typename std::iterator_traits::value_type Number; + _random_bits::Initializer::init(core, begin, end); + } + /// \brief Returns a random real number from the range [0, 1) /// /// It returns a random real number from the range [0, 1). The diff --git a/test/random_test.cc b/test/random_test.cc --- a/test/random_test.cc +++ b/test/random_test.cc @@ -24,6 +24,8 @@ ///\todo To be extended /// +int seed_array[] = {1, 2}; + int main() { double a=lemon::rnd(); @@ -34,4 +36,10 @@ //Does gamma work with integer k? a=lemon::rnd.gamma(4.0,0); a=lemon::rnd.poisson(.5); + + lemon::rnd.seed(100); + lemon::rnd.seed(seed_array, seed_array + + (sizeof(seed_array) / sizeof(seed_array[0]))); + + return 0; }