mirror of https://github.com/vitalif/openscad
clarify that its not nondeterministic, we are supporting older systems
where the C++/boost random_device stuff doesn't work. boost random_device in particular has a lot of issues with old versions not working, with -lboost_random not being installed by default, etc, that complicate the build too much.felipesanches-svg
parent
8aa349b15f
commit
3825a72499
14
src/func.cc
14
src/func.cc
|
@ -34,6 +34,14 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "stl-utils.h"
|
#include "stl-utils.h"
|
||||||
#include "printutils.h"
|
#include "printutils.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
Random numbers
|
||||||
|
|
||||||
|
Newer versions of boost/C++ include a non-deterministic random_device and
|
||||||
|
auto/bind()s for random function objects, but we are supporting older systems.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <boost/random/mersenne_twister.hpp>
|
#include <boost/random/mersenne_twister.hpp>
|
||||||
#include <boost/random/uniform_real_distribution.hpp>
|
#include <boost/random/uniform_real_distribution.hpp>
|
||||||
|
|
||||||
|
@ -47,9 +55,7 @@ int process_id = getpid();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
boost::random::mt19937 deterministic_rng;
|
boost::random::mt19937 deterministic_rng;
|
||||||
// this is technically not non-deterministic, but boost::random::random_device
|
boost::random::mt19937 lessdeterministic_rng( std::time(0) + process_id );
|
||||||
// has non-header library and/or version issues that would complicate the build
|
|
||||||
boost::random::mt19937 nondeterministic_rng( std::time(0) + process_id );
|
|
||||||
|
|
||||||
AbstractFunction::~AbstractFunction()
|
AbstractFunction::~AbstractFunction()
|
||||||
{
|
{
|
||||||
|
@ -177,7 +183,7 @@ Value builtin_rands(const Context *, const std::vector<std::string>&, const std:
|
||||||
if ( deterministic ) {
|
if ( deterministic ) {
|
||||||
vec.push_back( Value( distributor( deterministic_rng ) ) );
|
vec.push_back( Value( distributor( deterministic_rng ) ) );
|
||||||
} else {
|
} else {
|
||||||
vec.push_back( Value( distributor( nondeterministic_rng ) ) );
|
vec.push_back( Value( distributor( lessdeterministic_rng ) ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue