[ODE] dRandInt Crash Fix

Jon Watte (ODE) hplus-ode at mindcontrol.org
Wed Jun 22 10:38:52 MST 2005


> important.  Frankly, I'm not quite sure why dRandInt even needs to use 
> doubles.  Wouldn't just doing dRand() % n give you a number between 0 
> and n?  Regardless, here's a fixed version of dRandInt:

Using modulo results in really bad distribution and noticeable patterns 
in your random generator. Using a division over the entire range results 
in better random numbers, and is no slower (modulo is as slow as division).

Personally, I wouldn't want to accept the code that hides the bug, 
because that just means that the latent bug in the random generator goes 
into hiding again, waiting to bite you next time. You may have to do a 
quick fix to get a demo done by tomorrow, but the ODE library certainly 
doesn't have the same pressure...

Cheers,

			/ h+



More information about the ODE mailing list