Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:02:06

0001 #ifndef BOOST_UTILITY_DETAIL_MINSTD_RAND_HPP_INCLUDED
0002 #define BOOST_UTILITY_DETAIL_MINSTD_RAND_HPP_INCLUDED
0003 
0004 // Copyright 2017 Peter Dimov
0005 //
0006 // Distributed under the Boost Software License, Version 1.0.
0007 //
0008 // See accompanying file LICENSE_1_0.txt or copy at
0009 // http://www.boost.org/LICENSE_1_0.txt
0010 //
0011 // An implementation of minstd_rand that does not require
0012 // the Random library
0013 
0014 #include <boost/cstdint.hpp>
0015 
0016 namespace boost
0017 {
0018 namespace detail
0019 {
0020 
0021 class minstd_rand
0022 {
0023 private:
0024 
0025     boost::uint_least32_t x_;
0026 
0027     enum { a = 48271, m = 2147483647 };
0028 
0029 public:
0030 
0031     minstd_rand(): x_( 1 )
0032     {
0033     }
0034 
0035     explicit minstd_rand( boost::uint_least32_t x ): x_( x % m )
0036     {
0037         if( x_ == 0 )
0038         {
0039             x_ = 1;
0040         }
0041     }
0042 
0043     boost::uint_least32_t operator()()
0044     {
0045         boost::uint_least64_t y = x_;
0046 
0047         y = ( a * y ) % m;
0048 
0049         x_ = static_cast<boost::uint_least32_t>( y );
0050 
0051         return x_;
0052     }
0053 };
0054 
0055 } // namespace detail
0056 } // namespace boost
0057 
0058 #endif // #ifndef BOOST_UTILITY_DETAIL_MINSTD_RAND_HPP_INCLUDED