Android random number generator fixes (use deterministic rng on android).
This commit is contained in:
@@ -18,6 +18,10 @@
|
||||
|
||||
#define NOMINMAX // for Windows
|
||||
|
||||
#ifdef ANDROID
|
||||
#error This file is not for android.
|
||||
#endif
|
||||
|
||||
#include "tools.h"
|
||||
#include <core/loghelper.h>
|
||||
#include <core/openssl_wrapper.h>
|
||||
@@ -26,8 +30,6 @@
|
||||
#include <boost/nondet_random.hpp>
|
||||
#include <boost/random/uniform_int.hpp>
|
||||
#include <boost/random/variate_generator.hpp>
|
||||
#include <set>
|
||||
#include <limits>
|
||||
|
||||
|
||||
using namespace std;
|
||||
@@ -68,27 +70,3 @@ void Tools::GetRand(int minValue, int maxValue, unsigned count, int *out)
|
||||
}
|
||||
}
|
||||
|
||||
void Tools::GetRandUnique(int minValue, int maxValue, unsigned count, int *out)
|
||||
{
|
||||
InitRandState();
|
||||
unsigned numCreated = 0;
|
||||
int *startPtr = out;
|
||||
set<int> tmpSet;
|
||||
for (unsigned i = 0; i < count; i++) {
|
||||
boost::uniform_int<> dist(minValue, maxValue - numCreated);
|
||||
boost::variate_generator<boost::random_device&, boost::uniform_int<> > gen(*g_rand_state, dist);
|
||||
*startPtr = gen();
|
||||
set<int>::const_iterator v = tmpSet.begin();
|
||||
set<int>::const_iterator end = tmpSet.end();
|
||||
while (v != end) {
|
||||
if (*v <= *startPtr) {
|
||||
(*startPtr)++;
|
||||
}
|
||||
++v;
|
||||
}
|
||||
tmpSet.insert(*startPtr);
|
||||
startPtr++;
|
||||
numCreated++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user