From 63c87af293dccb7a339cc3e2e2ba33d41c8c13c2 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 4 Nov 2016 13:42:11 +0100 Subject: [PATCH] Split constructor of Random --- Random_numbers/include/CGAL/Random.h | 11 ++++++++--- Random_numbers/include/CGAL/Random_impl.h | 20 ++++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Random_numbers/include/CGAL/Random.h b/Random_numbers/include/CGAL/Random.h index cfd314f1275..dc85ebb6874 100644 --- a/Random_numbers/include/CGAL/Random.h +++ b/Random_numbers/include/CGAL/Random.h @@ -46,6 +46,10 @@ namespace CGAL { + namespace internal { + struct Random_print_seed{}; + } + class Random { public: // types @@ -65,8 +69,9 @@ public: {} }; // creation - CGAL_EXPORT Random( const char* = 0); - CGAL_EXPORT Random( unsigned int seed); + CGAL_EXPORT Random( ); + CGAL_EXPORT Random( internal::Random_print_seed ); + CGAL_EXPORT Random( unsigned int seed ); // seed CGAL_EXPORT unsigned int get_seed ( ) const; @@ -232,7 +237,7 @@ public: inline Random& get_default_random() { #if (defined( CGAL_TEST_SUITE ) || defined( CGAL_PRINT_SEED )) && !defined(CGAL_HEADER_ONLY) - CGAL_STATIC_THREAD_LOCAL_VARIABLE(Random, default_random, "print seed"); + CGAL_STATIC_THREAD_LOCAL_VARIABLE(Random, default_random, internal::Random_print_seed() )); #else CGAL_STATIC_THREAD_LOCAL_VARIABLE_0(Random, default_random); #endif diff --git a/Random_numbers/include/CGAL/Random_impl.h b/Random_numbers/include/CGAL/Random_impl.h index ac336c8078b..012a15293c2 100644 --- a/Random_numbers/include/CGAL/Random_impl.h +++ b/Random_numbers/include/CGAL/Random_impl.h @@ -40,16 +40,28 @@ namespace CGAL { // constructors CGAL_INLINE_FUNCTION Random:: -Random( const char* print_seed /* = 0 */ ) +Random() : val(0) { // get system's time std::time_t s; std::time( &s); seed = (unsigned int)s; - if(print_seed != 0) { - std::cerr << "CGAL::Random()::get_seed() = " << seed << std::endl; - } + // initialize random numbers generator + rng.seed(static_cast(seed)); + random_value = get_int(0, 1<<15); +} + +CGAL_INLINE_FUNCTION +Random:: +Random(internal::Random_print_seed) + : val(0) +{ + // get system's time + std::time_t s; + std::time( &s); + seed = (unsigned int)s; + std::cerr << "CGAL::Random()::get_seed() = " << seed << std::endl; // initialize random numbers generator rng.seed(static_cast(seed)); random_value = get_int(0, 1<<15);