V0.8: backport $random fix.

Back port a $random fix from development.
This commit is contained in:
Cary R 2008-12-08 18:38:20 -08:00 committed by Stephen Williams
parent ec85377d13
commit 918b0a410f
1 changed files with 9 additions and 3 deletions

View File

@ -79,7 +79,7 @@ long rtl_dist_uniform(long*seed, long start, long end)
}
else
{
i = (unsigned long) (r-1);
i = - ( (unsigned long) (-(r - 1)) );
}
if (i<start) i = start;
if (i>=end) i = end-1;
@ -94,7 +94,7 @@ long rtl_dist_uniform(long*seed, long start, long end)
}
else
{
i = (unsigned long) (r-1);
i = - ( (unsigned long) (-(r - 1)) );
}
if (i<=start) i = start+1;
if (i>end) i = end;
@ -110,7 +110,13 @@ long rtl_dist_uniform(long*seed, long start, long end)
}
else
{
i = (unsigned long) (r-1);
/* At least some compilers will notice that (r-1)
is <0 when castling to unsigned long and
replace the result with a zero. This causes
much wrongness, so do the casting to the
positive version and invert it back. */
i = - ( (unsigned long) (-(r - 1)) );
}
}