Seeding random sequence
authorBalazs Dezso <deba@inf.elte.hu>
Thu, 20 Mar 2008 17:15:35 +0100
changeset 10281563e019fa4
parent 101 70f3967ca6eb
child 104 cdbba181b786
Seeding random sequence
lemon/random.h
test/random_test.cc
     1.1 --- a/lemon/random.h	Thu Mar 20 12:12:24 2008 +0000
     1.2 +++ b/lemon/random.h	Thu Mar 20 17:15:35 2008 +0100
     1.3 @@ -575,6 +575,26 @@
     1.4        return *this;
     1.5      }
     1.6  
     1.7 +    /// \brief Seeding random sequence
     1.8 +    ///
     1.9 +    /// Seeding the random sequence. The current number type will be
    1.10 +    /// converted to the architecture word type.
    1.11 +    template <typename Number>
    1.12 +    void seed(Number seed) { 
    1.13 +      _random_bits::Initializer<Number, Word>::init(core, seed);
    1.14 +    }
    1.15 +
    1.16 +    /// \brief Seeding random sequence
    1.17 +    ///
    1.18 +    /// Seeding the random sequence. The given range should contain
    1.19 +    /// any number type and the numbers will be converted to the
    1.20 +    /// architecture word type.
    1.21 +    template <typename Iterator>
    1.22 +    void seed(Iterator begin, Iterator end) { 
    1.23 +      typedef typename std::iterator_traits<Iterator>::value_type Number;
    1.24 +      _random_bits::Initializer<Number, Word>::init(core, begin, end);
    1.25 +    }
    1.26 +
    1.27      /// \brief Returns a random real number from the range [0, 1)
    1.28      ///
    1.29      /// It returns a random real number from the range [0, 1). The
     2.1 --- a/test/random_test.cc	Thu Mar 20 12:12:24 2008 +0000
     2.2 +++ b/test/random_test.cc	Thu Mar 20 17:15:35 2008 +0100
     2.3 @@ -24,6 +24,8 @@
     2.4  ///\todo To be extended
     2.5  ///
     2.6  
     2.7 +int seed_array[] = {1, 2};
     2.8 +
     2.9  int main()
    2.10  {
    2.11    double a=lemon::rnd();
    2.12 @@ -34,4 +36,10 @@
    2.13    //Does gamma work with integer k?
    2.14    a=lemon::rnd.gamma(4.0,0);
    2.15    a=lemon::rnd.poisson(.5);
    2.16 +
    2.17 +  lemon::rnd.seed(100);
    2.18 +  lemon::rnd.seed(seed_array, seed_array + 
    2.19 +		  (sizeof(seed_array) / sizeof(seed_array[0])));
    2.20 +
    2.21 +  return 0;
    2.22  }