[ODE] dRandInt Crash Fix

Adam D. Moss adam at gimp.org
Wed Jun 22 17:51:08 MST 2005

Colin Bonstead wrote:
> Yup, we are using D3D and we're not setting the D3DCREATE_FPU_PRESERVE 
> flag.  I thought we set it back to full precision in a few sections in 
> the code, but now I can't find them.  Anyway, I know ODE wasn't getting 
> it switched so I'm sure it was using 24 bit precision. 

Right, that'd probably be the problem then...

 > So yeah, I would
> much rather have an integer based rand.

I'm quite fond of the xor-folding mod-taking dRandInt posted earlier,
having run it through a small battery of tests now.

n.b. ODE's dRand function is int-based and adequately random for ODE's
needs; the aforementioned dRandInt just leverages that without using
floating-point (like the original dRandInt) or damaging the size of
the range/domain (like the other proposed dRandInt).

But the only practical advantages it has over the existing dRandInt are:
1) D3D damaged-precision users don't get rare random crashes.
2) It's probably faster (but I haven't checked), mostly by avoiding
the hideous double->int cast.

That's probably enough to warrant becoming the default dRandInt(),
if no-one has strong opinions about it...

Adam D. Moss   -   adam at gimp.org

More information about the ODE mailing list