Merge pull request #1283 from Azaezel/randiiiiiii

corrects getrandom to behave as documented.
This commit is contained in:
Azaezel 2015-04-24 11:43:42 -05:00 committed by Daniel Buckmaster
parent 656c04abc7
commit f8d41a2b96

View file

@ -1019,7 +1019,7 @@ F32 mRandF()
return gRandGen.randF(); return gRandGen.randF();
} }
DefineConsoleFunction( getRandom, F32, (S32 a, S32 b), (1, 0), DefineConsoleFunction(getRandom, F32, (S32 a, S32 b), (S32_MAX, S32_MAX),
"( int a, int b ) " "( int a, int b ) "
"@brief Returns a random number based on parameters passed in..\n\n" "@brief Returns a random number based on parameters passed in..\n\n"
"If no parameters are passed in, getRandom() will return a float between 0.0 and 1.0. If one " "If no parameters are passed in, getRandom() will return a float between 0.0 and 1.0. If one "
@ -1033,11 +1033,11 @@ DefineConsoleFunction( getRandom, F32, (S32 a, S32 b), (1, 0),
"@see setRandomSeed\n" "@see setRandomSeed\n"
"@ingroup Random" ) "@ingroup Random" )
{ {
if (b == 0) if (a != S32_MAX)
return F32(gRandGen.randI(0,getMax( a, 0 )));
else
{ {
if (b != 0) if (b == S32_MAX)
return F32(gRandGen.randI(0, getMax(a, 0)));
else
{ {
S32 min = a; S32 min = a;
S32 max = b; S32 max = b;
@ -1047,7 +1047,7 @@ DefineConsoleFunction( getRandom, F32, (S32 a, S32 b), (1, 0),
min = max; min = max;
max = t; max = t;
} }
return F32(gRandGen.randI(min,max)); return F32(gRandGen.randI(min, max));
} }
} }
return gRandGen.randF(); return gRandGen.randF();