El Thursday 31 January 2008 16:41:55 DC Fennell escribió: > Hello everybody, > > I believe the get_random() function in range under osgParticle should be: > minimum + (maximum - minimum) * rand() / (RAND_MAX + 1); > It is written as: > > minimum + (maximum - minimum) * rand() / RAND_MAX; > > If you expect the values returned (as specified in the comments) to be > between min and max (min < x < max), then this function could give > incorrect results, since there are instances where rand() returns RAND_MAX. > > Is the intent of this function, in mathematical terms, to return (min, max) > or (min, max] ? > > This question applies to get_random_sqrtf() as well. > > Thanks. > > Chris.
I think it is taken directly from a known recomendation from the book "Numerical Recipes in C: The Art of Scientific Computing". It is mentioned in the man page of the rand() function: "If you want to generate a random integer between 1 and 10, you should always do it by using high-order bits, as in j = 1 + (int) (10.0 * (rand() / (RAND_MAX + 1.0))); and never by anything resembling j = 1 + (rand() % 10); (which uses lower-order bits)." I think it was more important for the original writer to get high quality random numbers than to match the exact range. Maybe the documentation should be changed in order to say that it returns min < x <= max, or the function, decrementing the max arg passed one unit, so the value returned could be min < x <= max-1 which would mean min < x < max when dealing with integers. _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

