mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 15:04:00 +00:00
Remove dependency on Random in operators_test.cpp
This commit is contained in:
parent
96fbce5759
commit
c88936800d
55
include/boost/utility/detail/minstd_rand.hpp
Normal file
55
include/boost/utility/detail/minstd_rand.hpp
Normal file
@ -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 <boost/cstdint.hpp>
|
||||
|
||||
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<boost::uint_least32_t>( y );
|
||||
|
||||
return x_;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_UTILITY_DETAIL_MINSTD_RAND_HPP_INCLUDED
|
@ -26,7 +26,7 @@
|
||||
#include <boost/config.hpp> // for BOOST_MSVC
|
||||
#include <boost/cstdlib.hpp> // for boost::exit_success
|
||||
#include <boost/operators.hpp> // for the tested items
|
||||
#include <boost/random/linear_congruential.hpp> // for boost::minstd_rand
|
||||
#include <boost/utility/detail/minstd_rand.hpp> // for boost::detail::minstd_rand
|
||||
#include <boost/test/test_tools.hpp> // for main
|
||||
|
||||
#include <iostream> // for std::cout (std::endl indirectly)
|
||||
@ -532,7 +532,7 @@ namespace
|
||||
template <class Big, class Small>
|
||||
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 <class Big, class Small>
|
||||
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<long, int>()(r);
|
||||
tester<long, signed char>()(r);
|
||||
tester<long, long>()(r);
|
||||
|
Loading…
x
Reference in New Issue
Block a user