1 /* 2 * Created by Martin on 30/08/2017. 3 * 4 * Distributed under the Boost Software License, Version 1.0. (See accompanying 5 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 */ 7 8 #include "catch_random_number_generator.h" 9 #include "catch_context.h" 10 #include "catch_interfaces_config.h" 11 12 #include <cstdlib> 13 14 namespace Catch { 15 seedRng(IConfig const & config)16 void seedRng( IConfig const& config ) { 17 if( config.rngSeed() != 0 ) 18 std::srand( config.rngSeed() ); 19 } rngSeed()20 unsigned int rngSeed() { 21 return getCurrentContext().getConfig()->rngSeed(); 22 } 23 operator ()(result_type n) const24 RandomNumberGenerator::result_type RandomNumberGenerator::operator()( result_type n ) const { 25 return std::rand() % n; 26 } operator ()() const27 RandomNumberGenerator::result_type RandomNumberGenerator::operator()() const { 28 return std::rand() % (max)(); 29 } 30 31 } 32