From 3b3ca6339ef679564540c634082155c1ed8bb1e7 Mon Sep 17 00:00:00 2001 From: lotodore Date: Sun, 27 Feb 2011 22:05:15 +0000 Subject: [PATCH] Cosmetic changes. --- src/engine/local_engine/tools.cpp | 35 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/engine/local_engine/tools.cpp b/src/engine/local_engine/tools.cpp index 3df7d05f..a3b50c60 100755 --- a/src/engine/local_engine/tools.cpp +++ b/src/engine/local_engine/tools.cpp @@ -45,7 +45,8 @@ struct nondet_rng : std::unary_function { nondet_rng(boost::random_device &state) : _state(state) {} }; -static inline void InitRandState() { +static inline void InitRandState() +{ if (!g_rand_state.get()) { g_rand_state.reset(new boost::random_device); } @@ -55,7 +56,7 @@ void Tools::ShuffleArrayNonDeterministic(int *inout, unsigned count) { InitRandState(); nondet_rng rand(*g_rand_state); - std::random_shuffle(&inout[0], &inout[count], rand); + random_shuffle(&inout[0], &inout[count], rand); } void Tools::GetRand(int minValue, int maxValue, unsigned count, int *out) @@ -65,7 +66,7 @@ void Tools::GetRand(int minValue, int maxValue, unsigned count, int *out) boost::variate_generator > gen(*g_rand_state, dist); int *startPtr = out; for (unsigned i = 0; i < count; i++) { - *startPtr++ = gen(); + *startPtr++ = gen(); } } @@ -74,22 +75,22 @@ void Tools::GetRandUnique(int minValue, int maxValue, unsigned count, int *out) InitRandState(); unsigned numCreated = 0; int *startPtr = out; - std::set tmpSet; + set tmpSet; for (unsigned i = 0; i < count; i++) { - boost::uniform_int<> dist(minValue, maxValue - numCreated); - boost::variate_generator > gen(*g_rand_state, dist); - *startPtr = gen(); - std::set::const_iterator v = tmpSet.begin(); - std::set::const_iterator end = tmpSet.end(); - while (v != end) { - if (*v <= *startPtr) { - (*startPtr)++; - } - ++v; + boost::uniform_int<> dist(minValue, maxValue - numCreated); + boost::variate_generator > gen(*g_rand_state, dist); + *startPtr = gen(); + set::const_iterator v = tmpSet.begin(); + set::const_iterator end = tmpSet.end(); + while (v != end) { + if (*v <= *startPtr) { + (*startPtr)++; } - tmpSet.insert(*startPtr); - startPtr++; - numCreated++; + ++v; + } + tmpSet.insert(*startPtr); + startPtr++; + numCreated++; } } #endif