diff --git a/CDT/include/CDT.h b/CDT/include/CDT.h index 11a4316f..66bc7f41 100644 --- a/CDT/include/CDT.h +++ b/CDT/include/CDT.h @@ -517,25 +517,33 @@ struct hash > namespace CDT { +namespace detail +{ + #ifdef CDT_CXX11_IS_SUPPORTED + +static mt19937 randGenerator(9001); inline void shuffle_indices(std::vector& indices) { - static mt19937 g(9001); - std::shuffle(indices.begin(), indices.end(), g); + std::shuffle(indices.begin(), indices.end(), randGenerator); } + #else + inline size_t randomCDT(const size_t i) { - static mt19937 g(9001); - return g() % i; + return randGenerator() % i; } inline void shuffle_indices(std::vector& indices) { std::random_shuffle(indices.begin(), indices.end(), randomCDT); } + #endif +} // namespace detail + //----------------------- // Triangulation methods //----------------------- @@ -550,6 +558,7 @@ void Triangulation::insertVertices( TGetVertexCoordX getX, TGetVertexCoordY getY) { + detail::randGenerator.seed(9001); // ensure deterministic behavior if(vertices.empty()) { addSuperTriangle(envelopBox(first, last, getX, getY)); @@ -573,7 +582,7 @@ void Triangulation::insertVertices( VertInd value = nExistingVerts; for(Iter it = ii.begin(); it != ii.end(); ++it, ++value) *it = value; - shuffle_indices(ii); + detail::shuffle_indices(ii); for(Iter it = ii.begin(); it != ii.end(); ++it) insertVertex(*it); break; diff --git a/CDT/include/CDT.hpp b/CDT/include/CDT.hpp index 9d8593cc..97ced6f9 100644 --- a/CDT/include/CDT.hpp +++ b/CDT/include/CDT.hpp @@ -21,7 +21,6 @@ typedef std::deque TriDeque; namespace detail { -static mt19937 randGen(9001); /// Needed for c++03 compatibility (no uniform initialization available) template @@ -659,7 +658,7 @@ TriInd Triangulation::walkTriangles( const Triangle& t = triangles[currTri]; found = true; // stochastic offset to randomize which edge we check first - const Index offset(detail::randGen() % 3); + const Index offset(detail::randGenerator() % 3); for(Index i_(0); i_ < Index(3); ++i_) { const Index i((i_ + offset) % 3);