[Boost-bugs] [Boost C++ Libraries] #3516: lagged fibonacci cannot be seeded with a value 0 - fails with assertion error

Subject: [Boost-bugs] [Boost C++ Libraries] #3516: lagged fibonacci cannot be seeded with a value 0 - fails with assertion error
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-10-09 18:26:56


#3516: lagged fibonacci cannot be seeded with a value 0 - fails with assertion
error
------------------------------------------------------------+---------------
 Reporter: Paul H. Isaacson <paul.isaacson@…> | Owner: no-maintainer
     Type: Bugs | Status: new
Milestone: Boost 1.41.0 | Component: random
  Version: Boost 1.40.0 | Severity: Problem
 Keywords: lagged fibonacci seed 0 |
------------------------------------------------------------+---------------
 When using the lagged_fibonacci607 and attempting to seed, the attached
 test program will either stop with an assertion error at line 57 of
 boost/random/linear_congruential.hpp, or if -DNDEBUG is used during
 compilation to disable assertions, the returned values are not in range.

 Seeding with a zero value should not cause such problems.


 {{{
 #include <stdlib.h>
 #include <stdio.h>
 #include <boost/random/lagged_fibonacci.hpp>

 using namespace std;

 boost::lagged_fibonacci607 lfrand;

 inline int fastrand (int range)
 {
   return ((int) range * lfrand());
 }

 main (int argc, char **argv)
 {
    unsigned int seed;

    if (argc < 2)
    {
      printf ("Usage lftest <seed>\n");
      exit (1);
    }

    sscanf (argv[1], "%d", &seed);
    printf ("using seed value %d\n", seed);

    lfrand.seed (seed);

    for (int n = 0; n < 1000000; n++)
    {
      int x = fastrand (10);
      if (x < 0 || x > 9)
        printf ("out of range random number[%d] = %d\n", n, x);
    }
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/3516>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:01 UTC