Hello all,
As I mentioned in earlier emails I've been playing around a bit with the
random number generators in the GSL.
I'm wondering if someone can advise on appropriate ways to generate
uniformly-distributed ints in the range [0,n-1]. My traditional way has
always been to take a function ranf() which returns a floating-point
number in [0,1), and do,
x = (int) (n*ranf());
But, if we suppose I have a function like the rand() function in C that
returns an int between 0 and RAND_MAX - 1, would it be appropriate to do,
x = rand()%n;
Or would this unduly affect the uniform distribution?
I note that the gsl_rng_uniform_int function uses a method like this
(simplifying slightly...;-):
do { x = rand()/(RAND_MAX/n); } while( x >= n);
Could someone advise? If they are equivalent, what about the speed of
these alternatives?
Many thanks,
-- Joe
_______________________________________________
Help-gsl mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gsl