]> git.lyx.org Git - lyx.git/blob - boost/boost/min_rand.hpp
complie fix
[lyx.git] / boost / boost / min_rand.hpp
1 //  Boost min_rand.hpp header file  ------------------------------------------//
2
3 //  (C) Copyright Beman Dawes 1998. Permission to copy, use, modify, sell and
4 //  distribute this software is granted provided this copyright notice appears
5 //  in all copies. This software is provided "as is" without express or implied
6 //  warranty, and with no claim as to its suitability for any purpose.
7
8 //  Version 1.1, 25 May 99  Add operator()() to meet Generator requirements
9 //  Version 1.0,  9 Nov 98  Initial version
10
11 #ifndef BOOST_MIN_RAND_HPP
12 #define BOOST_MIN_RAND_HPP
13
14 #include <cassert>
15
16 namespace boost {
17
18 //  min_rand  ----------------------------------------------------------------//
19
20 //  see min_rand.html for documentation
21
22 class min_rand {
23
24   //  Don't even think about changing the values of the constants below.
25   //  See the article cited in the documentation for rationale.
26   enum constants {
27     modulus = 2147483647L,
28     multiplier = 48271L,          // 16807L for original "minimal standard"
29     validation = 399268537L,      // 1043618065L for original "minimal standard"
30     q = modulus / multiplier, 
31     r = modulus % multiplier
32     };
33
34   long value;                     // invariant: 0 < value <= modulus
35
36  public:
37
38   //  compiler generated copy constructor and operator= are valid and useful
39
40   explicit min_rand( long seed_value=1 ) : value( seed_value )
41                               { assert( value > 0 && value <= modulus ); }
42
43   operator long() const       { return value; }
44   double fvalue() const       { return double(value) / modulus; }
45
46   min_rand& operator=( long new_value ) {
47                                 value = new_value;
48                                 assert( value > 0 && value <= modulus );
49                                 return *this;
50                               }
51
52   long operator++()           { value = multiplier*(value%q) - r*(value/q);
53                                 if ( value <= 0 ) value += modulus;
54                                 assert( value > 0 && value <= modulus );
55                                 return value;
56                               }
57   long operator++(int)        { long temp = value; operator++(); return temp; }
58
59   long ten_thousandth() const { return validation; }
60
61   //  satisfy std::RandomNumberGenerator and std::Generator requirements:
62   typedef long  argument_type;
63   typedef long  result_type;
64   long operator()( long n )   { return operator++() % n; }
65   long operator()()           { return operator++(); }
66
67   }; // min_rand
68
69 } // namespace boost
70
71 #endif  // BOOST_MIN_RAND_HPP