attempt to fix oos related to random number generation
This commit is contained in:
parent
1633a80b69
commit
792ab1b7bc
|
@ -15,9 +15,12 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include "platform_util.h"
|
#include "platform_util.h"
|
||||||
|
#include "math_util.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace Shared::Graphics;
|
||||||
|
|
||||||
namespace Shared { namespace Util {
|
namespace Shared { namespace Util {
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
@ -71,7 +74,7 @@ int RandomGen::randRange(int min, int max){
|
||||||
// int res = streflop::Random<true, false, float>(min, max); // streflop
|
// int res = streflop::Random<true, false, float>(min, max); // streflop
|
||||||
//#else
|
//#else
|
||||||
int diff= max-min;
|
int diff= max-min;
|
||||||
int res= min + static_cast<int>(static_cast<float>(diff+1)*RandomGen::rand() / m);
|
int res= min + static_cast<int>(truncateDecimal<double>(static_cast<double>(diff+1))*RandomGen::rand() / m);
|
||||||
//#endif
|
//#endif
|
||||||
assert(res>=min && res<=max);
|
assert(res>=min && res<=max);
|
||||||
if(res < min || res > max) {
|
if(res < min || res > max) {
|
||||||
|
@ -98,6 +101,7 @@ float RandomGen::randRange(float min, float max){
|
||||||
//#else
|
//#else
|
||||||
float rand01= static_cast<float>(RandomGen::rand())/(m-1);
|
float rand01= static_cast<float>(RandomGen::rand())/(m-1);
|
||||||
float res= min+(max-min)*rand01;
|
float res= min+(max-min)*rand01;
|
||||||
|
res = truncateDecimal<float>(res);
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
assert(res>=min && res<=max);
|
assert(res>=min && res<=max);
|
||||||
|
|
Loading…
Reference in New Issue