From a2e766f136f7692d79bcbadbd52b3198d1fdd6e8 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Sun, 28 Feb 2016 08:20:28 +0100 Subject: [PATCH] Print the seed of CGAL::default_random in the testsuite or when CGAL_PRINT_SEED is defined --- Random_numbers/include/CGAL/Random.h | 4 +++- Random_numbers/include/CGAL/Random_impl.h | 19 +++++++++++++++++++ Random_numbers/src/CGAL/Random.cpp | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Random_numbers/include/CGAL/Random.h b/Random_numbers/include/CGAL/Random.h index 665dd78cb23..b794ab1be33 100644 --- a/Random_numbers/include/CGAL/Random.h +++ b/Random_numbers/include/CGAL/Random.h @@ -66,6 +66,7 @@ public: // creation CGAL_EXPORT Random( ); CGAL_EXPORT Random( unsigned int seed); + CGAL_EXPORT Random(char*); // seed CGAL_EXPORT unsigned int get_seed ( ) const; @@ -237,7 +238,8 @@ CGAL_EXPORT extern Random default_random; #ifdef CGAL_HEADER_ONLY inline Random& get_default_random() { - static Random default_random; + static Random default_random("default"); + std::cerr << "get_default_random()" << std::endl; return default_random; } #else // CGAL_HEADER_ONLY diff --git a/Random_numbers/include/CGAL/Random_impl.h b/Random_numbers/include/CGAL/Random_impl.h index 16cb9e0cbd3..17cbd503c94 100644 --- a/Random_numbers/include/CGAL/Random_impl.h +++ b/Random_numbers/include/CGAL/Random_impl.h @@ -62,6 +62,25 @@ Random( unsigned int seed) random_value = get_int(0, 1<<15); } + +CGAL_INLINE_FUNCTION +Random:: +Random(char* ) + : val(0) +{ + // get system's time + std::time_t s; + std::time( &s); + seed = (unsigned int)s; + +#if defined( CGAL_TEST_SUITE ) || defined( CGAL_PRINT_SEED ) + std::cerr << "default_random::get_seed() = " << seed << std::endl; +#endif + // initialize random numbers generator + rng.seed(static_cast(seed)); + random_value = get_int(0, 1<<15); +} + // seed CGAL_INLINE_FUNCTION unsigned int diff --git a/Random_numbers/src/CGAL/Random.cpp b/Random_numbers/src/CGAL/Random.cpp index 471accc5128..c88e1b7de65 100644 --- a/Random_numbers/src/CGAL/Random.cpp +++ b/Random_numbers/src/CGAL/Random.cpp @@ -29,7 +29,7 @@ namespace CGAL { -Random default_random; + Random default_random = Random("default"); } //namespace CGAL