]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/utility/detail/minstd_rand.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / utility / detail / minstd_rand.hpp
1 #ifndef BOOST_UTILITY_DETAIL_MINSTD_RAND_HPP_INCLUDED
2 #define BOOST_UTILITY_DETAIL_MINSTD_RAND_HPP_INCLUDED
3
4 // Copyright 2017 Peter Dimov
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 //
8 // An implementation of minstd_rand that does not require
9 // the Random library
10
11 #include <boost/cstdint.hpp>
12
13 namespace boost
14 {
15 namespace detail
16 {
17
18 class minstd_rand
19 {
20 private:
21
22 boost::uint_least32_t x_;
23
24 enum { a = 48271, m = 2147483647 };
25
26 public:
27
28 minstd_rand(): x_( 1 )
29 {
30 }
31
32 explicit minstd_rand( boost::uint_least32_t x ): x_( x % m )
33 {
34 if( x_ == 0 )
35 {
36 x_ = 1;
37 }
38 }
39
40 boost::uint_least32_t operator()()
41 {
42 boost::uint_least64_t y = x_;
43
44 y = ( a * y ) % m;
45
46 x_ = static_cast<boost::uint_least32_t>( y );
47
48 return x_;
49 }
50 };
51
52 } // namespace detail
53 } // namespace boost
54
55 #endif // #ifndef BOOST_UTILITY_DETAIL_MINSTD_RAND_HPP_INCLUDED