cmMath.h.c : Added cmRandXXX() functions.
This commit is contained in:
parent
e65764d7a4
commit
83841f4934
28
cmMath.c
28
cmMath.c
@ -391,3 +391,31 @@ double cmFfSwapULLongToDouble( unsigned long long v )
|
|||||||
u.u = cmSwap64(v);
|
u.u = cmSwap64(v);
|
||||||
return u.f;
|
return u.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int cmRandInt( int min, int max )
|
||||||
|
{
|
||||||
|
assert( min <= max );
|
||||||
|
int offs = max - min;
|
||||||
|
return min + cmMax(0,cmMin(offs,(int)round(offs * (double)rand() / RAND_MAX)));
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned cmRandUInt( unsigned min, unsigned max )
|
||||||
|
{
|
||||||
|
assert( min <= max );
|
||||||
|
unsigned offs = max - min;
|
||||||
|
return min + cmMax(0,cmMin(offs,(unsigned)round(offs * (double)rand() / RAND_MAX)));
|
||||||
|
}
|
||||||
|
|
||||||
|
float cmRandFloat( float min, float max )
|
||||||
|
{
|
||||||
|
assert( min <= max );
|
||||||
|
float offs = max - min;
|
||||||
|
return min + cmMax(0,cmMin(offs,(float)(offs * (double)rand() / RAND_MAX)));
|
||||||
|
}
|
||||||
|
|
||||||
|
double cmRandDouble( double min, double max )
|
||||||
|
{
|
||||||
|
assert( min <= max );
|
||||||
|
double offs = max - min;
|
||||||
|
return min + cmMax(0,cmMin(offs,(offs * (double)rand() / RAND_MAX)));
|
||||||
|
}
|
||||||
|
7
cmMath.h
7
cmMath.h
@ -62,6 +62,9 @@ float cmFfSwapUIntToFloat( unsigned v );
|
|||||||
unsigned long long cmFfSwapDoubleToULLong( double v );
|
unsigned long long cmFfSwapDoubleToULLong( double v );
|
||||||
double cmFfSwapULLongToDouble( unsigned long long v );
|
double cmFfSwapULLongToDouble( unsigned long long v );
|
||||||
|
|
||||||
|
//=================================================================
|
||||||
|
int cmRandInt( int min, int max );
|
||||||
|
unsigned cmRandUInt( unsigned min, unsigned max );
|
||||||
|
float cmRandFloat( float min, float max );
|
||||||
|
double cmRandDouble( double min, double max );
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user