summaryrefslogtreecommitdiff
path: root/src/func.cc
diff options
context:
space:
mode:
authordon bright <hugh.m.bright@gmail.com>2013-01-06 16:03:37 (GMT)
committerdon bright <hugh.m.bright@gmail.com>2013-01-06 16:03:37 (GMT)
commit30922740a1287230e79aaeb03d3166079fc321d9 (patch)
treec8c4172c2b65f4699ce8a097e58172155ab9a67d /src/func.cc
parent84c6d45eaac2d04d4e855dddb88bb208e531451e (diff)
remove boost::random_device, move min/max out of the random generator loop
Diffstat (limited to 'src/func.cc')
-rw-r--r--src/func.cc19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/func.cc b/src/func.cc
index a4d48e2..de9060d 100644
--- a/src/func.cc
+++ b/src/func.cc
@@ -34,14 +34,13 @@
#include <algorithm>
#include "stl-utils.h"
#include "printutils.h"
-#include <boost/random/random_device.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_real_distribution.hpp>
-boost::random::random_device nondeterministic_rng;
-boost::random::mt19937 deterministic_rng;
-
-#include "random_device.cpp"
+boost::random::mt19937 deterministic_prng;
+// not technically non-deterministic, but boost::random::random_device has
+// non-header library and/or version issues that would complicate the build
+boost::random::mt19937 nondeterministic_prng( std::time(0) );
AbstractFunction::~AbstractFunction()
{
@@ -161,15 +160,15 @@ Value builtin_rands(const Context *, const std::vector<std::string>&, const std:
return Value();
}
+ double min = std::min( args[0].toDouble(), args[1].toDouble() );
+ double max = std::max( args[0].toDouble(), args[1].toDouble() );
+ boost::random::uniform_real_distribution<> distributor( min, max );
Value::VectorType vec;
for (int i=0; i<args[2].toDouble(); i++) {
- double min = std::min( args[0].toDouble(), args[1].toDouble() );
- double max = std::max( args[0].toDouble(), args[1].toDouble() );
- boost::random::uniform_real_distribution<> dist( min, max );
if ( deterministic ) {
- vec.push_back( Value( dist( deterministic_rng ) ) );
+ vec.push_back( Value( distributor( deterministic_rng ) ) );
} else {
- vec.push_back( Value( dist( nondeterministic_rng ) ) );
+ vec.push_back( Value( distributor( nondeterministic_rng ) ) );
}
}
contact: Jan Huwald // Impressum