I believe there is bug in random_number_generator when you request a random number between 0 and 1. For example:
> random_number_generator rgen(...); > cout << rgen(1) << endl; // causes assertion failure
I encountered this problem when using random_number_generator in conjuction with the random_sample_n algorithm.
I have attached a simple patch which catches the case when the parameter is 1. If anyone can tell me whether this is a reasonable fix, I would be grateful.
Thanks,
David J. Pearce
*** random_number_generator.old 2003-02-25 16:41:26.000000000 +0000
--- random_number_generator.hpp 2003-02-25 16:42:00.000000000 +0000
***************
*** 50,56 ****
// assignment is disallowed because there is a reference member
result_type operator()(argument_type n) {
! return uniform_int<base_type>(_rng, 0, n-1)();
}
private:
--- 50,60 ----
// assignment is disallowed because there is a reference member
result_type operator()(argument_type n) {
! if(n == 1) {
! return 0;
! } else {
! return uniform_int<base_type>(_rng, 0, n-1)();
! }
}
private:
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
