|
@@ -391,3 +391,31 @@ double cmFfSwapULLongToDouble( unsigned long long v )
|
391
|
391
|
u.u = cmSwap64(v);
|
392
|
392
|
return u.f;
|
393
|
393
|
}
|
|
394
|
+
|
|
395
|
+int cmRandInt( int min, int max )
|
|
396
|
+{
|
|
397
|
+ assert( min <= max );
|
|
398
|
+ int offs = max - min;
|
|
399
|
+ return min + cmMax(0,cmMin(offs,(int)round(offs * (double)rand() / RAND_MAX)));
|
|
400
|
+}
|
|
401
|
+
|
|
402
|
+unsigned cmRandUInt( unsigned min, unsigned max )
|
|
403
|
+{
|
|
404
|
+ assert( min <= max );
|
|
405
|
+ unsigned offs = max - min;
|
|
406
|
+ return min + cmMax(0,cmMin(offs,(unsigned)round(offs * (double)rand() / RAND_MAX)));
|
|
407
|
+}
|
|
408
|
+
|
|
409
|
+float cmRandFloat( float min, float max )
|
|
410
|
+{
|
|
411
|
+ assert( min <= max );
|
|
412
|
+ float offs = max - min;
|
|
413
|
+ return min + cmMax(0,cmMin(offs,(float)(offs * (double)rand() / RAND_MAX)));
|
|
414
|
+}
|
|
415
|
+
|
|
416
|
+double cmRandDouble( double min, double max )
|
|
417
|
+{
|
|
418
|
+ assert( min <= max );
|
|
419
|
+ double offs = max - min;
|
|
420
|
+ return min + cmMax(0,cmMin(offs,(offs * (double)rand() / RAND_MAX)));
|
|
421
|
+}
|