Opened 13 years ago
Closed 13 years ago
#3516 closed Bugs (fixed)
lagged fibonacci cannot be seeded with a value 0 - fails with assertion error
| Reported by: | Owned by: | No-Maintainer | |
|---|---|---|---|
| Milestone: | Boost 1.41.0 | Component: | random |
| Version: | Boost 1.40.0 | Severity: | Problem |
| Keywords: | lagged fibonacci seed 0 | Cc: |
Description
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);
}
}
Change History (3)
comment:1 by , 13 years ago
comment:2 by , 13 years ago
I think that the correct way to fix this is to change the wrap-around algorithm in linear_congruential so that it can handle zero.
comment:3 by , 13 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.

This is a limitation of the seeding algorithm. lagged_fibonacci::seed is documented to use minstd_rand0 which cannot be seeded with 0.