From c88936800d6c967b0306a52aa44f80e29f187675 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 23 Dec 2017 06:19:43 +0200 Subject: [PATCH] Remove dependency on Random in operators_test.cpp --- include/boost/utility/detail/minstd_rand.hpp | 55 ++++++++++++++++++++ test/operators_test.cpp | 8 +-- 2 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 include/boost/utility/detail/minstd_rand.hpp diff --git a/include/boost/utility/detail/minstd_rand.hpp b/include/boost/utility/detail/minstd_rand.hpp new file mode 100644 index 0000000..6c858f6 --- /dev/null +++ b/include/boost/utility/detail/minstd_rand.hpp @@ -0,0 +1,55 @@ +#ifndef BOOST_UTILITY_DETAIL_MINSTD_RAND_HPP_INCLUDED +#define BOOST_UTILITY_DETAIL_MINSTD_RAND_HPP_INCLUDED + +// Copyright 2017 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// +// An implementation of minstd_rand that does not require +// the Random library + +#include + +namespace boost +{ +namespace detail +{ + +class minstd_rand +{ +private: + + boost::uint_least32_t x_; + + enum { a = 48271, m = 2147483647 }; + +public: + + minstd_rand(): x_( 1 ) + { + } + + explicit minstd_rand( boost::uint_least32_t x ): x_( x % m ) + { + if( x_ == 0 ) + { + x_ = 1; + } + } + + boost::uint_least32_t operator()() + { + boost::uint_least64_t y = x_; + + y = ( a * y ) % m; + + x_ = static_cast( y ); + + return x_; + } +}; + +} // namespace detail +} // namespace boost + +#endif // #ifndef BOOST_UTILITY_DETAIL_MINSTD_RAND_HPP_INCLUDED diff --git a/test/operators_test.cpp b/test/operators_test.cpp index f445945..b279677 100644 --- a/test/operators_test.cpp +++ b/test/operators_test.cpp @@ -26,7 +26,7 @@ #include // for BOOST_MSVC #include // for boost::exit_success #include // for the tested items -#include // for boost::minstd_rand +#include // for boost::detail::minstd_rand #include // for main #include // for std::cout (std::endl indirectly) @@ -532,7 +532,7 @@ namespace template struct tester { - void operator()(boost::minstd_rand& randomizer) const + void operator()(boost::detail::minstd_rand& randomizer) const { Big b1 = Big( randomizer() ); Big b2 = Big( randomizer() ); @@ -546,7 +546,7 @@ namespace template struct tester_left { - void operator()(boost::minstd_rand& randomizer) const + void operator()(boost::detail::minstd_rand& randomizer) const { Big b1 = Big( randomizer() ); Small s = Small( randomizer() ); @@ -620,7 +620,7 @@ test_main( int , char * [] ) for (int n = 0; n < 1000; ++n) // was 10,000 but took too long (Beman) { - boost::minstd_rand r; + boost::detail::minstd_rand r; tester()(r); tester()(r); tester()(r);