Commit 281864aa by Paolo Carlini Committed by Paolo Carlini

random: Trivial uglification fixes.

2006-06-06  Paolo Carlini  <pcarlini@suse.de>

	* include/tr1/random: Trivial uglification fixes.
	* include/tr1/random.tcc: Likewise.

	* include/tr1/random (subtract_with_carry<>::
	subtract_with_carry(_IntType)): Fix parameter type to unsigned long.
	(subtract_with_carry<>::seed(_IntType)): Likewise.
	* include/tr1/random.tcc (subtract_with_carry<>::seed(_IntType)):
	Adjust.

From-SVN: r114440
parent 8cf0db2b
2006-06-06 Paolo Carlini <pcarlini@suse.de>
* include/tr1/random: Trivial uglification fixes.
* include/tr1/random.tcc: Likewise.
* include/tr1/random (subtract_with_carry<>::
subtract_with_carry(_IntType)): Fix parameter type to unsigned long.
(subtract_with_carry<>::seed(_IntType)): Likewise.
* include/tr1/random.tcc (subtract_with_carry<>::seed(_IntType)):
Adjust.
2006-06-05 Paolo Carlini <pcarlini@suse.de> 2006-06-05 Paolo Carlini <pcarlini@suse.de>
* include/tr1/random (mersenne_twister<>::seed()): Fix per * include/tr1/random (mersenne_twister<>::seed()): Fix per
......
...@@ -62,17 +62,17 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -62,17 +62,17 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
*/ */
namespace _Private namespace _Private
{ {
// Type selectors -- are these already implemeted elsewhere? // Type selectors -- are these already implemented elsewhere?
template<bool, typename _TpTrue, typename _TpFalse> template<bool, typename _TpTrue, typename _TpFalse>
struct _Select struct _Select
{ {
typedef _TpTrue Type; typedef _TpTrue _Type;
}; };
template<typename _TpTrue, typename _TpFalse> template<typename _TpTrue, typename _TpFalse>
struct _Select<false, _TpTrue, _TpFalse> struct _Select<false, _TpTrue, _TpFalse>
{ {
typedef _TpFalse Type; typedef _TpFalse _Type;
}; };
/* /*
...@@ -97,7 +97,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -97,7 +97,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
}; };
/* /*
* Converts a value generated by the adapted random number genereator into a * Converts a value generated by the adapted random number generator into a
* value in the input domain for the dependent random number distribution. * value in the input domain for the dependent random number distribution.
* *
* Because the type traits are compile time constants only the appropriate * Because the type traits are compile time constants only the appropriate
...@@ -154,10 +154,10 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -154,10 +154,10 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
public: public:
/** /**
* Constructs a variate generator with the uniform random number * Constructs a variate generator with the uniform random number
* generator @p eng for the random distribution @p d. * generator @p __eng for the random distribution @p __dist.
* *
* @throws Any exceptions which may thrown by the copy constructors of the * @throws Any exceptions which may thrown by the copy constructors of
* @p _Generator or @p _Dist objects. * the @p _Generator or @p _Dist objects.
*/ */
variate_generator(engine_type __eng, distribution_type __dist) variate_generator(engine_type __eng, distribution_type __dist)
: _M_engine(__eng), _M_dist(__dist) { } : _M_engine(__eng), _M_dist(__dist) { }
...@@ -269,66 +269,67 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -269,66 +269,67 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* A random number generator that produces pseudorandom numbers using the * A random number generator that produces pseudorandom numbers using the
* linear function @f$x_{i+1}\leftarrow(ax_{i} + c) \bmod m @f$. * linear function @f$x_{i+1}\leftarrow(ax_{i} + c) \bmod m @f$.
* *
* The template parameter @p UIntType must be an unsigned integral type large * The template parameter @p _UIntType must be an unsigned integral type
* enough to store values up to (m-1). If the template parameter @p m is 0, * large enough to store values up to (__m-1). If the template parameter
* the modulus @p m used is std::numeric_limits<UIntType>::max() plus 1. * @p __m is 0, the modulus @p __m used is
* Otherwise, the template parameters @p a and @p c must be less than @p m. * std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template
* parameters @p __a and @p __c must be less than @p __m.
* *
* The size of the state is @f$ 1 @f$. * The size of the state is @f$ 1 @f$.
*/ */
template<class UIntType, UIntType a, UIntType c, UIntType m> template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
class linear_congruential class linear_congruential
{ {
__glibcxx_class_requires(UIntType, _UnsignedIntegerConcept) __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
// __glibcpp_class_requires(a < m && c < m) // __glibcpp_class_requires(__a < __m && __c < __m)
public: public:
/** The type of the generated random value. */ /** The type of the generated random value. */
typedef UIntType result_type; typedef _UIntType result_type;
/** The multiplier. */ /** The multiplier. */
static const UIntType multiplier = a; static const _UIntType multiplier = __a;
/** An increment. */ /** An increment. */
static const UIntType increment = c; static const _UIntType increment = __c;
/** The modulus. */ /** The modulus. */
static const UIntType modulus = m; static const _UIntType modulus = __m;
/** /**
* Constructs a %linear_congruential random number generator engine with * Constructs a %linear_congruential random number generator engine with
* seed @p s. The default seed value is 1. * seed @p __s. The default seed value is 1.
* *
* @param s The initial seed value. * @param __s The initial seed value.
*/ */
explicit linear_congruential(unsigned long s = 1); explicit linear_congruential(unsigned long __s = 1);
/** /**
* Constructs a %linear_congruential random number generator engine * Constructs a %linear_congruential random number generator engine
* seeded from the generator function @g. * seeded from the generator function @p __g.
* *
* @param g The seed generator function. * @param __g The seed generator function.
*/ */
template<class Gen> template<class _Gen>
linear_congruential(Gen& g); linear_congruential(_Gen& __g);
/** /**
* Resets the %linear_congruential random number generator engine sequence * Reseeds the %linear_congruential random number generator engine
* to @p. * sequence to the seed @g __s.
* *
* @param s The new seed. * @param __s The new seed.
*/ */
void void
seed(unsigned long s = 1); seed(unsigned long __s = 1);
/** /**
* Resets the %linear_congruential random number generator engine sequence * Reseeds the %linear_congruential random number generator engine
* using a vlaue from the generator function @g. * sequence using values from the generator function @p __g.
* *
* @param g the seed generator function. * @param __g the seed generator function.
*/ */
template<class Gen> template<class _Gen>
void void
seed(Gen& g) seed(_Gen& __g)
{ seed(g, typename is_fundamental<Gen>::type()); } { seed(__g, typename is_fundamental<_Gen>::type()); }
/** /**
* Gets the smallest possible value in the output range. * Gets the smallest possible value in the output range.
...@@ -352,72 +353,74 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -352,72 +353,74 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* Compares two linear congruential random number generator objects of the * Compares two linear congruential random number generator objects of the
* same type for equality. * same type for equality.
* *
* @param lhs A linear congruential random number generator object. * @param __lhs A linear congruential random number generator object.
* @param rhs Another linear congruential random number generator object. * @param __rhs Another linear congruential random number generator obj.
* *
* @returns true if the two objects are equal, false otherwise. * @returns true if the two objects are equal, false otherwise.
*/ */
friend bool friend bool
operator==(const linear_congruential& lhs, const linear_congruential& rhs) operator==(const linear_congruential& __lhs,
{ return lhs.m_x == rhs.m_x; } const linear_congruential& __rhs)
{ return __lhs._M_x == __rhs._M_x; }
/** /**
* Compares two linear congruential random number generator objects of the * Compares two linear congruential random number generator objects of the
* same type for inequality. * same type for inequality.
* *
* @param lhs A linear congruential random number generator object. * @param __lhs A linear congruential random number generator object.
* @param rhs Another linear congruential random number generator object. * @param __rhs Another linear congruential random number generator obj.
* *
* @returns true if the two objects are not equal, false otherwise. * @returns true if the two objects are not equal, false otherwise.
*/ */
friend bool friend bool
operator!=(const linear_congruential& lhs, const linear_congruential& rhs) operator!=(const linear_congruential& __lhs,
{ return !(lhs == rhs); } const linear_congruential& __rhs)
{ return !(__lhs == __rhs); }
/** /**
* Writes the textual representation of the state x(i) of x to @p os. * Writes the textual representation of the state x(i) of x to @p __os.
* *
* @param os The output stream. * @param __os The output stream.
* @param lcr A linear_congruential random number generator. * @param __lcr A linear_congruential random number generator.
* @returns os. * @returns __os.
*/ */
template<typename CharT, typename Traits> template<typename _CharT, typename _Traits>
friend std::basic_ostream<CharT, Traits>& friend std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<CharT, Traits>& os, operator<<(std::basic_ostream<_CharT, _Traits>& __os,
const linear_congruential& lcr) const linear_congruential& __lcr)
{ return os << lcr.m_x; } { return __os << __lcr._M_x; }
/** /**
* Sets the state of the engine by reading its textual * Sets the state of the engine by reading its textual
* representation from @p is. * representation from @p __is.
* *
* The textual representation must have been previously written using an * The textual representation must have been previously written using an
* output stream whose imbued locale and whose type's template * output stream whose imbued locale and whose type's template
* specialization arguments CharT and Traits were the same as those of * specialization arguments _CharT and _Traits were the same as those of
* @p is. * @p __is.
* *
* @param is The input stream. * @param __is The input stream.
* @param lcr A linear_congruential random number generator. * @param __lcr A linear_congruential random number generator.
* @returns os. * @returns __is.
*/ */
template<typename CharT, typename Traits> template<typename _CharT, typename _Traits>
friend std::basic_istream<CharT, Traits>& friend std::basic_istream<_CharT, _Traits>&
operator>>(std::basic_istream<CharT, Traits>& is, operator>>(std::basic_istream<_CharT, _Traits>& __is,
linear_congruential& lcr) linear_congruential& __lcr)
{ return is >> lcr.m_x; } { return __is >> __lcr._M_x; }
private: private:
template<class Gen> template<class _Gen>
void void
seed(Gen& g, true_type) seed(_Gen& __g, true_type)
{ return seed(static_cast<unsigned long>(g)); } { return seed(static_cast<unsigned long>(__g)); }
template<class Gen> template<class _Gen>
void void
seed(Gen& g, false_type); seed(_Gen& __g, false_type);
private: private:
UIntType m_x; _UIntType _M_x;
}; };
/** /**
...@@ -456,52 +459,53 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -456,52 +459,53 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* @var output_c The second left-shift tempering matrix mask. * @var output_c The second left-shift tempering matrix mask.
* @var output_l The second right-shift tempering matrix parameter. * @var output_l The second right-shift tempering matrix parameter.
*/ */
template<class UIntType, int w, int n, int m, int r, template<class _UIntType, int __w, int __n, int __m, int __r,
UIntType a, int u, int s, UIntType b, int t, UIntType c, int l> _UIntType __a, int __u, int __s, _UIntType __b, int __t,
_UIntType __c, int __l>
class mersenne_twister class mersenne_twister
{ {
__glibcxx_class_requires(UIntType, _UnsignedIntegerConcept) __glibcxx_class_requires(_UIntType, _UnsignedIntegerConcept)
public: public:
// types // types
typedef UIntType result_type ; typedef _UIntType result_type ;
// parameter values // parameter values
static const int word_size = w; static const int word_size = __w;
static const int state_size = n; static const int state_size = __n;
static const int shift_size = m; static const int shift_size = __m;
static const int mask_bits = r; static const int mask_bits = __r;
static const UIntType parameter_a = a; static const _UIntType parameter_a = __a;
static const int output_u = u; static const int output_u = __u;
static const int output_s = s; static const int output_s = __s;
static const UIntType output_b = b; static const _UIntType output_b = __b;
static const int output_t = t; static const int output_t = __t;
static const UIntType output_c = c; static const _UIntType output_c = __c;
static const int output_l = l; static const int output_l = __l;
// constructors and member function // constructors and member function
mersenne_twister() mersenne_twister()
{ seed(); } { seed(); }
explicit explicit
mersenne_twister(unsigned long value) mersenne_twister(unsigned long __value)
{ seed(value); } { seed(__value); }
template<class Gen> template<class _Gen>
mersenne_twister(Gen& g) mersenne_twister(_Gen& __g)
{ seed(g); } { seed(__g); }
void void
seed() seed()
{ seed(5489UL); } { seed(5489UL); }
void void
seed(unsigned long value); seed(unsigned long __value);
template<class Gen> template<class _Gen>
void void
seed(Gen& g) seed(_Gen& __g)
{ seed(g, typename is_fundamental<Gen>::type()); } { seed(__g, typename is_fundamental<_Gen>::type()); }
result_type result_type
min() const min() const
...@@ -514,18 +518,18 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -514,18 +518,18 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
operator()(); operator()();
private: private:
template<class Gen> template<class _Gen>
void void
seed(Gen& g, true_type) seed(_Gen& __g, true_type)
{ return seed(static_cast<unsigned long>(g)); } { return seed(static_cast<unsigned long>(__g)); }
template<class Gen> template<class _Gen>
void void
seed(Gen& g, false_type); seed(_Gen& __g, false_type);
private: private:
UIntType _M_x[state_size]; _UIntType _M_x[state_size];
int _M_p; int _M_p;
}; };
/** /**
...@@ -565,7 +569,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -565,7 +569,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* @var _M_p Current index of x(i - r). * @var _M_p Current index of x(i - r).
* @endif * @endif
*/ */
template<typename _IntType, _IntType m, int s, int r> template<typename _IntType, _IntType __m, int __s, int __r>
class subtract_with_carry class subtract_with_carry
{ {
__glibcxx_class_requires(_IntType, _IntegerConcept) __glibcxx_class_requires(_IntType, _IntegerConcept)
...@@ -575,9 +579,9 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -575,9 +579,9 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
typedef _IntType result_type; typedef _IntType result_type;
// parameter values // parameter values
static const _IntType modulus = m; static const _IntType modulus = __m;
static const int long_lag = r; static const int long_lag = __r;
static const int short_lag = s; static const int short_lag = __s;
public: public:
/** /**
...@@ -592,16 +596,16 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -592,16 +596,16 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* generator. * generator.
*/ */
explicit explicit
subtract_with_carry(_IntType __value) subtract_with_carry(unsigned long __value)
{ this->seed(__value); } { this->seed(__value); }
/** /**
* Constructs a % subtract_with_carry random number generator seeded from * Constructs a % subtract_with_carry random number generator seeded from
* the PAD iterated by [__first, last). * the PAD iterated by [__first, last).
*/ */
template<class Gen> template<class _Gen>
subtract_with_carry(Gen& g) subtract_with_carry(_Gen& __g)
{ this->seed(g); } { this->seed(__g); }
/** /**
* Seeds the initial state @f$ x_0 @f$ of the random number generator. * Seeds the initial state @f$ x_0 @f$ of the random number generator.
...@@ -619,16 +623,16 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -619,16 +623,16 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* If @f$ x_{-1} = 0 @f$ set carry to 1, otherwise sets carry to 0. * If @f$ x_{-1} = 0 @f$ set carry to 1, otherwise sets carry to 0.
*/ */
void void
seed(_IntType __value = 19780503); seed(unsigned long __value = 19780503);
/** /**
* Seeds the initial state @f$ x_0 @f$ of the % subtract_with_carry * Seeds the initial state @f$ x_0 @f$ of the % subtract_with_carry
* random number generator. * random number generator.
*/ */
template<class Gen> template<class _Gen>
void void
seed(Gen& g) seed(_Gen& __g)
{ seed(g, typename is_fundamental<Gen>::type()); } { seed(__g, typename is_fundamental<_Gen>::type()); }
/** /**
* Gets the inclusive minimum value of the range of random integers * Gets the inclusive minimum value of the range of random integers
...@@ -667,7 +671,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -667,7 +671,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
const subtract_with_carry& __rhs) const subtract_with_carry& __rhs)
{ {
return ((__lhs._M_x[0] == __rhs._M_x[0]) return ((__lhs._M_x[0] == __rhs._M_x[0])
&& (__lhs._M_x[r-1] == __rhs._M_x[r-1])); && (__lhs._M_x[__r - 1] == __rhs._M_x[__r - 1]));
} }
/** /**
...@@ -687,7 +691,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -687,7 +691,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/** /**
* Inserts the current state of a % subtract_with_carry random number * Inserts the current state of a % subtract_with_carry random number
* genator engine @p x into the output stream @p os. * genator engine @p x into the output stream @p __os.
* *
* @param __os An output stream. * @param __os An output stream.
* @param __x A % subtract_with_carry random number generator engine. * @param __x A % subtract_with_carry random number generator engine.
...@@ -700,14 +704,14 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -700,14 +704,14 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
operator<<(basic_ostream<_CharT, _Traits>& __os, operator<<(basic_ostream<_CharT, _Traits>& __os,
const subtract_with_carry& __x) const subtract_with_carry& __x)
{ {
std::copy(__x._M_x, __x._M_x + r, std::copy(__x._M_x, __x._M_x + __r,
std::ostream_iterator<_IntType>(__os, " ")); std::ostream_iterator<_IntType>(__os, " "));
return __os << __x._M_carry; return __os << __x._M_carry;
} }
/** /**
* Extracts the current state of a % subtract_with_carry random number * Extracts the current state of a % subtract_with_carry random number
* gerator engine @p x from the input stream @p is. * gerator engine @p x from the input stream @p __is.
* *
* @param __is An input stream. * @param __is An input stream.
* @param __x A % subtract_with_carry random number generator engine. * @param __x A % subtract_with_carry random number generator engine.
...@@ -720,21 +724,21 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -720,21 +724,21 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
operator>>(basic_istream<_CharT, _Traits>& __is, operator>>(basic_istream<_CharT, _Traits>& __is,
subtract_with_carry& __x) subtract_with_carry& __x)
{ {
for (int __i = 0; __i < r; ++__i) for (int __i = 0; __i < __r; ++__i)
__is >> __x._M_x[__i]; __is >> __x._M_x[__i];
__is >> __x._M_carry; __is >> __x._M_carry;
return __is; return __is;
} }
private: private:
template<class Gen> template<class _Gen>
void void
seed(Gen& g, true_type) seed(_Gen& __g, true_type)
{ return seed(static_cast<unsigned long>(g)); } { return seed(static_cast<unsigned long>(__g)); }
template<class Gen> template<class _Gen>
void void
seed(Gen& g, false_type); seed(_Gen& __g, false_type);
private: private:
int _M_p; int _M_p;
...@@ -747,9 +751,9 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -747,9 +751,9 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* Produces random numbers from some base engine by discarding blocks of * Produces random numbers from some base engine by discarding blocks of
* data. * data.
* *
* 0 <= @p r <= @p p * 0 <= @p __r <= @p __p
*/ */
template<class UniformRandomNumberGenerator, int p, int r> template<class _UniformRandomNumberGenerator, int __p, int __r>
class discard_block class discard_block
{ {
// __glibcxx_class_requires(typename base_type::result_type, // __glibcxx_class_requires(typename base_type::result_type,
...@@ -757,13 +761,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -757,13 +761,13 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
public: public:
/** The type of the underlying generator engine. */ /** The type of the underlying generator engine. */
typedef UniformRandomNumberGenerator base_type; typedef _UniformRandomNumberGenerator base_type;
/** The type of the generated random value. */ /** The type of the generated random value. */
typedef typename base_type::result_type result_type; typedef typename base_type::result_type result_type;
// parameter values // parameter values
static const int block_size = p; static const int block_size = __p;
static const int used_block = r; static const int used_block = __r;
/** /**
* Constructs a default %discard_block engine. * Constructs a default %discard_block engine.
...@@ -779,26 +783,26 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -779,26 +783,26 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* Copies an existing base class random number geenerator. * Copies an existing base class random number geenerator.
* @param rng An existing (base class) engine object. * @param rng An existing (base class) engine object.
*/ */
explicit discard_block(const base_type& rng) explicit discard_block(const base_type& __rng)
: _M_b(rng) , _M_n(0) { } : _M_b(__rng) , _M_n(0) { }
/** /**
* Seed constructs a %discard_block engine. * Seed constructs a %discard_block engine.
* *
* Constructs the underlying generator engine seeded with @p s. * Constructs the underlying generator engine seeded with @p __s.
* @param s A seed value for the base class engine. * @param __s A seed value for the base class engine.
*/ */
explicit discard_block(unsigned long s) explicit discard_block(unsigned long __s)
: _M_b(s), _M_n(0) { } : _M_b(__s), _M_n(0) { }
/** /**
* Generator constructs a %discard_block engine. * Generator constructs a %discard_block engine.
* *
* @param g A seed generator function. * @param __g A seed generator function.
*/ */
template<class Gen> template<class _Gen>
discard_block(Gen& g) discard_block(_Gen& __g)
: _M_b(g), _M_n(0) { } : _M_b(__g), _M_n(0) { }
/** /**
* Reseeds the %discard_block object with the default seed for the * Reseeds the %discard_block object with the default seed for the
...@@ -813,12 +817,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -813,12 +817,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/** /**
* Reseeds the %discard_block object with the given seed generator * Reseeds the %discard_block object with the given seed generator
* function. * function.
* @param g A seed generator function. * @param __g A seed generator function.
*/ */
template<class Gen> template<class _Gen>
void seed(Gen& g) void seed(_Gen& __g)
{ {
_M_b.seed(g); _M_b.seed(__g);
_M_n = 0; _M_n = 0;
} }
...@@ -882,7 +886,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -882,7 +886,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/** /**
* Inserts the current state of a %discard_block random number * Inserts the current state of a %discard_block random number
* genator engine @p x into the output stream @p os. * genator engine @p x into the output stream @p __os.
* *
* @param __os An output stream. * @param __os An output stream.
* @param __x A %discard_block random number generator engine. * @param __x A %discard_block random number generator engine.
...@@ -898,7 +902,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -898,7 +902,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/** /**
* Extracts the current state of a % subtract_with_carry random number * Extracts the current state of a % subtract_with_carry random number
* gerator engine @p x from the input stream @p is. * gerator engine @p x from the input stream @p __is.
* *
* @param __is An input stream. * @param __is An input stream.
* @param __x A %discard_block random number generator engine. * @param __x A %discard_block random number generator engine.
...@@ -941,43 +945,43 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -941,43 +945,43 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* A random number generator adaptor class that combines two random number * A random number generator adaptor class that combines two random number
* generator engines into a single output sequence. * generator engines into a single output sequence.
*/ */
template<class UniformRandomNumberGenerator1, int s1, template<class _UniformRandomNumberGenerator1, int __s1,
class UniformRandomNumberGenerator2, int s2> class _UniformRandomNumberGenerator2, int __s2>
class xor_combine class xor_combine
{ {
// __glibcxx_class_requires(typename UniformRandomNumberGenerator1:: // __glibcxx_class_requires(typename _UniformRandomNumberGenerator1::
// result_type, ArithmeticTypeConcept); // result_type, ArithmeticTypeConcept);
// __glibcxx_class_requires(typename UniformRandomNumberGenerator2:: // __glibcxx_class_requires(typename _UniformRandomNumberGenerator2::
// result_type, ArithmeticTypeConcept); // result_type, ArithmeticTypeConcept);
public: public:
/** The type of the the first underlying generator engine. */ /** The type of the the first underlying generator engine. */
typedef UniformRandomNumberGenerator1 base1_type; typedef _UniformRandomNumberGenerator1 base1_type;
/** The type of the the second underlying generator engine. */ /** The type of the the second underlying generator engine. */
typedef UniformRandomNumberGenerator2 base2_type; typedef _UniformRandomNumberGenerator2 base2_type;
/** The type of the generated random value. */ /** The type of the generated random value. */
typedef typename _Private::_Select< typedef typename _Private::_Select<
(sizeof(base1_type) > sizeof(base2_type)), (sizeof(base1_type) > sizeof(base2_type)),
base1_type, base1_type,
base2_type base2_type
>::Type result_type; >::_Type result_type;
// parameter values // parameter values
static const int shift1 = s1; static const int shift1 = __s1;
static const int shift2 = s2; static const int shift2 = __s2;
// constructors and member function // constructors and member function
xor_combine() { } xor_combine() { }
xor_combine(const base1_type& rng1, const base2_type& rng2) xor_combine(const base1_type& __rng1, const base2_type& __rng2)
: _M_b1(rng1), _M_b2(rng2) { } : _M_b1(__rng1), _M_b2(__rng2) { }
xor_combine(unsigned long s) xor_combine(unsigned long __s)
: _M_b1(s), _M_b2(s + 1) { } : _M_b1(__s), _M_b2(__s + 1) { }
template<class Gen> template<class _Gen>
xor_combine(Gen& g) xor_combine(_Gen& __g)
: _M_b1(g), _M_b2(g) { } : _M_b1(__g), _M_b2(__g) { }
void void
seed() seed()
...@@ -986,12 +990,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -986,12 +990,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
_M_b2.seed(); _M_b2.seed();
} }
template<class Gen> template<class _Gen>
void void
seed(Gen& g) seed(_Gen& __g)
{ {
_M_b1.seed(g); _M_b1.seed(__g);
_M_b2.seed(g); _M_b2.seed(__g);
} }
const base1_type& const base1_type&
...@@ -1050,7 +1054,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1050,7 +1054,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/** /**
* Inserts the current state of a %xor_combine random number * Inserts the current state of a %xor_combine random number
* genator engine @p x into the output stream @p os. * genator engine @p x into the output stream @p __os.
* *
* @param __os An output stream. * @param __os An output stream.
* @param __x A %xor_combine random number generator engine. * @param __x A %xor_combine random number generator engine.
...@@ -1066,7 +1070,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1066,7 +1070,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/** /**
* Extracts the current state of a %xor_combine random number * Extracts the current state of a %xor_combine random number
* gerator engine @p x from the input stream @p is. * gerator engine @p x from the input stream @p __is.
* *
* @param __is An input stream. * @param __is An input stream.
* @param __x A %xor_combine random number generator engine. * @param __x A %xor_combine random number generator engine.
...@@ -1101,15 +1105,15 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1101,15 +1105,15 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
typedef unsigned int result_type; typedef unsigned int result_type;
// constructors, destructors and member functions // constructors, destructors and member functions
explicit random_device(const std::string& token = "unimplemented"); explicit random_device(const std::string& __token = "unimplemented");
result_type min() const; result_type min() const;
result_type max() const; result_type max() const;
double entropy() const; double entropy() const;
result_type operator()(); result_type operator()();
private: private:
random_device(const random_device &); random_device(const random_device&);
void operator=(const random_device &); void operator=(const random_device&);
}; };
/* @} */ // group tr1_random_generators /* @} */ // group tr1_random_generators
...@@ -1212,7 +1216,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1212,7 +1216,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/** /**
* Extracts a %unform_int random number distribution * Extracts a %unform_int random number distribution
* @p u from the input stream @p is. * @p u from the input stream @p __is.
* *
* @param __is An input stream. * @param __is An input stream.
* @param __u A %uniform_int random number generator engine. * @param __u A %uniform_int random number generator engine.
...@@ -1246,7 +1250,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1246,7 +1250,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/** /**
* Constructs a Bernoulli distribution with likelihood @p p. * Constructs a Bernoulli distribution with likelihood @p p.
* *
* @param p [IN] The likelihood of a true result being returned. Must * @param __p [IN] The likelihood of a true result being returned. Must
* be in the interval @f$ [0, 1] @f$. * be in the interval @f$ [0, 1] @f$.
*/ */
explicit explicit
...@@ -1299,7 +1303,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1299,7 +1303,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/** /**
* Inserts a %bernoulli_distribution random number distribution * Inserts a %bernoulli_distribution random number distribution
* @p x into the output stream @p os. * @p x into the output stream @p __os.
* *
* @param __os An output stream. * @param __os An output stream.
* @param __x A %bernoulli_distribution random number distribution. * @param __x A %bernoulli_distribution random number distribution.
...@@ -1315,7 +1319,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1315,7 +1319,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/** /**
* Extracts a %bernoulli_distribution random number distribution * Extracts a %bernoulli_distribution random number distribution
* @p u from the input stream @p is. * @p u from the input stream @p __is.
* *
* @param __is An input stream. * @param __is An input stream.
* @param __u A %bernoulli_distribution random number generator engine. * @param __u A %bernoulli_distribution random number generator engine.
...@@ -1358,7 +1362,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1358,7 +1362,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
} }
/** /**
* Gets the distribution parameter @p. * Gets the distribution parameter @p p.
*/ */
_RealType _RealType
p() const p() const
...@@ -1389,7 +1393,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1389,7 +1393,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/** /**
* Inserts a %geometric_distribution random number distribution * Inserts a %geometric_distribution random number distribution
* @p x into the output stream @p os. * @p x into the output stream @p __os.
* *
* @param __os An output stream. * @param __os An output stream.
* @param __x A %geometric_distribution random number distribution. * @param __x A %geometric_distribution random number distribution.
...@@ -1405,7 +1409,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1405,7 +1409,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/** /**
* Extracts a %geometric_distribution random number distribution * Extracts a %geometric_distribution random number distribution
* @p u from the input stream @p is. * @p u from the input stream @p __is.
* *
* @param __is An input stream. * @param __is An input stream.
* @param __u A %geometric_distribution random number generator engine. * @param __u A %geometric_distribution random number generator engine.
...@@ -1454,11 +1458,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1454,11 +1458,12 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/** /**
* Constructs a uniform_real object. * Constructs a uniform_real object.
* *
* @param min [IN] The lower bound of the distribution. * @param __min [IN] The lower bound of the distribution.
* @param max [IN] The upper bound of the distribution. * @param __max [IN] The upper bound of the distribution.
*/ */
explicit explicit
uniform_real(_RealType min = _RealType(0), _RealType max = _RealType(1)); uniform_real(_RealType __min = _RealType(0),
_RealType __max = _RealType(1));
result_type result_type
min() const; min() const;
...@@ -1475,7 +1480,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1475,7 +1480,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/** /**
* Inserts a %uniform_real random number distribution @p x into the * Inserts a %uniform_real random number distribution @p x into the
* output stream @p os. * output stream @p __os.
* *
* @param __os An output stream. * @param __os An output stream.
* @param __x A %uniform_real random number distribution. * @param __x A %uniform_real random number distribution.
...@@ -1491,7 +1496,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1491,7 +1496,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/** /**
* Extracts a %unform_real random number distribution * Extracts a %unform_real random number distribution
* @p u from the input stream @p is. * @p u from the input stream @p __is.
* *
* @param __is An input stream. * @param __is An input stream.
* @param __u A %uniform_real random number generator engine. * @param __u A %uniform_real random number generator engine.
...@@ -1564,7 +1569,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1564,7 +1569,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/** /**
* Inserts a %exponential_distribution random number distribution * Inserts a %exponential_distribution random number distribution
* @p x into the output stream @p os. * @p x into the output stream @p __os.
* *
* @param __os An output stream. * @param __os An output stream.
* @param __x A %exponential_distribution random number distribution. * @param __x A %exponential_distribution random number distribution.
...@@ -1580,7 +1585,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -1580,7 +1585,7 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/** /**
* Extracts a %exponential_distribution random number distribution * Extracts a %exponential_distribution random number distribution
* @p u from the input stream @p is. * @p u from the input stream @p __is.
* *
* @param __is An input stream. * @param __is An input stream.
* @param __u A %exponential_distribution random number generator engine. * @param __u A %exponential_distribution random number generator engine.
......
...@@ -46,93 +46,94 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -46,93 +46,94 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
// //
// Preconditions: a > 0, m > 0. // Preconditions: a > 0, m > 0.
// //
template<typename _Tp, _Tp a, _Tp c, _Tp m, bool _m_is_zero> template<typename _Tp, _Tp __a, _Tp __c, _Tp __m, bool>
struct Mod struct _Mod
{ {
static _Tp static _Tp
calc(_Tp x) __calc(_Tp __x)
{ {
if (a == 1) if (__a == 1)
x %= m; __x %= __m;
else else
{ {
static const _Tp q = m / a; static const _Tp __q = __m / __a;
static const _Tp r = m % a; static const _Tp __r = __m % __a;
_Tp t1 = a * (x % q); _Tp __t1 = __a * (__x % __q);
_Tp t2 = r * (x / q); _Tp __t2 = __r * (__x / __q);
if (t1 >= t2) if (__t1 >= __t2)
x = t1 - t2; __x = __t1 - __t2;
else else
x = m - t2 + t1; __x = __m - __t2 + __t1;
} }
if (c != 0) if (__c != 0)
{ {
const _Tp d = m - x; const _Tp __d = __m - __x;
if (d > c) if (__d > __c)
x += c; __x += __c;
else else
x = c - d; __x = __c - __d;
} }
return x; return __x;
} }
}; };
// Special case for m==0 -- use unsigned integer overflow as modulo // Special case for m == 0 -- use unsigned integer overflow as modulo
// operator. // operator.
template<typename _Tp, _Tp a, _Tp c, _Tp m> template<typename _Tp, _Tp __a, _Tp __c, _Tp __m>
struct Mod<_Tp, a, c, m, true> struct _Mod<_Tp, __a, __c, __m, true>
{ {
static _Tp static _Tp
calc(_Tp x) __calc(_Tp __x)
{ return a * x + c; } { return __a * __x + __c; }
}; };
// Dispatch based on modulus value to prevent divide-by-zero compile-time // Dispatch based on modulus value to prevent divide-by-zero compile-time
// errors when m == 0. // errors when m == 0.
template<typename _Tp, _Tp a, _Tp c, _Tp m> template<typename _Tp, _Tp __a, _Tp __c, _Tp __m>
inline _Tp inline _Tp
mod(_Tp x) __mod(_Tp __x)
{ return Mod<_Tp, a, c, m, m == 0>::calc(x); } { return _Mod<_Tp, __a, __c, __m, __m == 0>::__calc(__x); }
// Like the above, for a==1, c==0, in terms of w. // Like the above, for a == 1, c == 0, in terms of w.
template<typename _Tp, _Tp w, bool> template<typename _Tp, _Tp __w, bool>
struct Mod_w struct _Mod_w
{ {
static _Tp static _Tp
calc(_Tp x) __calc(_Tp __x)
{ return x % (_Tp(1) << w); } { return __x % (_Tp(1) << __w); }
}; };
template<typename _Tp, _Tp w> template<typename _Tp, _Tp __w>
struct Mod_w<_Tp, w, true> struct _Mod_w<_Tp, __w, true>
{ {
static _Tp static _Tp
calc(_Tp x) __calc(_Tp __x)
{ return x; } { return __x; }
}; };
template<typename _Tp, _Tp w> template<typename _Tp, _Tp __w>
inline _Tp inline _Tp
mod_w(_Tp x) __mod_w(_Tp __x)
{ return Mod_w<_Tp, w, w == std::numeric_limits<_Tp>::digits>::calc(x); } { return _Mod_w<_Tp, __w,
__w == std::numeric_limits<_Tp>::digits>::__calc(__x); }
// Selector to return the maximum value possible that will fit in // Selector to return the maximum value possible that will fit in
// @p w bits of @p _Tp. // @p __w bits of @p _Tp.
template<typename _Tp, _Tp w, bool> template<typename _Tp, _Tp __w, bool>
struct Max_w struct _Max_w
{ {
static _Tp static _Tp
value() __value()
{ return (_Tp(1) << w) - 1; } { return (_Tp(1) << __w) - 1; }
}; };
template<typename _Tp, _Tp w> template<typename _Tp, _Tp __w>
struct Max_w<_Tp, w, true> struct _Max_w<_Tp, __w, true>
{ {
static _Tp static _Tp
value() __value()
{ return std::numeric_limits<_Tp>::max(); } { return std::numeric_limits<_Tp>::max(); }
}; };
...@@ -140,53 +141,53 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -140,53 +141,53 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
/** /**
* Constructs the LCR engine with integral seed @p x0. * Constructs the LCR engine with integral seed @p __x0.
*/ */
template<class UIntType, UIntType a, UIntType c, UIntType m> template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
linear_congruential<UIntType, a, c, m>:: linear_congruential<_UIntType, __a, __c, __m>::
linear_congruential(unsigned long x0) linear_congruential(unsigned long __x0)
{ this->seed(x0); } { this->seed(__x0); }
/** /**
* Constructs the LCR engine with seed generated from @p g. * Constructs the LCR engine with seed generated from @p __g.
*/ */
template<class UIntType, UIntType a, UIntType c, UIntType m> template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
template<class Gen> template<class _Gen>
linear_congruential<UIntType, a, c, m>:: linear_congruential<_UIntType, __a, __c, __m>::
linear_congruential(Gen& g) linear_congruential(_Gen& __g)
{ this->seed(g); } { this->seed(__g); }
/** /**
* Seeds the LCR with integral value @p x0, adjusted so that the * Seeds the LCR with integral value @p __x0, adjusted so that the
* ring identity is never a member of the convergence set. * ring identity is never a member of the convergence set.
*/ */
template<class UIntType, UIntType a, UIntType c, UIntType m> template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
void void
linear_congruential<UIntType, a, c, m>:: linear_congruential<_UIntType, __a, __c, __m>::
seed(unsigned long x0) seed(unsigned long __x0)
{ {
if ((_Private::mod<UIntType, 1, 0, m>(c) == 0) if ((_Private::__mod<_UIntType, 1, 0, __m>(__c) == 0)
&& (_Private::mod<UIntType, 1, 0, m>(x0) == 0)) && (_Private::__mod<_UIntType, 1, 0, __m>(__x0) == 0))
m_x = _Private::mod<UIntType, 1, 0, m>(1); _M_x = _Private::__mod<_UIntType, 1, 0, __m>(1);
else else
m_x = _Private::mod<UIntType, 1, 0, m>(x0); _M_x = _Private::__mod<_UIntType, 1, 0, __m>(__x0);
} }
/** /**
* Seeds the LCR engine with a value generated by @p g. * Seeds the LCR engine with a value generated by @p __g.
*/ */
template<class UIntType, UIntType a, UIntType c, UIntType m> template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
template<class Gen> template<class _Gen>
void void
linear_congruential<UIntType, a, c, m>:: linear_congruential<_UIntType, __a, __c, __m>::
seed(Gen& g, false_type) seed(_Gen& __g, false_type)
{ {
UIntType x0 = g(); _UIntType __x0 = __g();
if ((_Private::mod<UIntType, 1, 0, m>(c) == 0) if ((_Private::__mod<_UIntType, 1, 0, __m>(__c) == 0)
&& (_Private::mod<UIntType, 1, 0, m>(x0) == 0)) && (_Private::__mod<_UIntType, 1, 0, __m>(__x0) == 0))
m_x = _Private::mod<UIntType, 1, 0, m>(1); _M_x = _Private::__mod<_UIntType, 1, 0, __m>(1);
else else
m_x = _Private::mod<UIntType, 1, 0, m>(x0); _M_x = _Private::__mod<_UIntType, 1, 0, __m>(__x0);
} }
/** /**
...@@ -194,135 +195,146 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -194,135 +195,146 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
* returned by operator(). The return value of this function does not * returned by operator(). The return value of this function does not
* change during the lifetime of the object.. * change during the lifetime of the object..
* *
* The minumum depends on the @p c parameter: if it is zero, the * The minumum depends on the @p __c parameter: if it is zero, the
* minimum generated must be > 0, otherwise 0 is allowed. * minimum generated must be > 0, otherwise 0 is allowed.
*/ */
template<class UIntType, UIntType a, UIntType c, UIntType m> template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
typename linear_congruential<UIntType, a, c, m>::result_type typename linear_congruential<_UIntType, __a, __c, __m>::result_type
linear_congruential<UIntType, a, c, m>:: linear_congruential<_UIntType, __a, __c, __m>::
min() const min() const
{ return (_Private::mod<UIntType, 1, 0, m>(c) == 0) ? 1 : 0; } { return (_Private::__mod<_UIntType, 1, 0, __m>(__c) == 0) ? 1 : 0; }
/** /**
* Gets the maximum possible value of the generated range. * Gets the maximum possible value of the generated range.
* *
* For a linear congruential generator, the maximum is always @p m - 1. * For a linear congruential generator, the maximum is always @p __m - 1.
*/ */
template<class UIntType, UIntType a, UIntType c, UIntType m> template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
typename linear_congruential<UIntType, a, c, m>::result_type typename linear_congruential<_UIntType, __a, __c, __m>::result_type
linear_congruential<UIntType, a, c, m>:: linear_congruential<_UIntType, __a, __c, __m>::
max() const max() const
{ return (m == 0) ? std::numeric_limits<UIntType>::max() : (m - 1); } { return (__m == 0) ? std::numeric_limits<_UIntType>::max() : (__m - 1); }
/** /**
* Gets the next generated value in sequence. * Gets the next generated value in sequence.
*/ */
template<class UIntType, UIntType a, UIntType c, UIntType m> template<class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
typename linear_congruential<UIntType, a, c, m>::result_type typename linear_congruential<_UIntType, __a, __c, __m>::result_type
linear_congruential<UIntType, a, c, m>:: linear_congruential<_UIntType, __a, __c, __m>::
operator()() operator()()
{ {
m_x = _Private::mod<UIntType, a, c, m>(m_x); _M_x = _Private::__mod<_UIntType, __a, __c, __m>(_M_x);
return m_x; return _M_x;
} }
template<class _UInt, int w, int n, int m, int r, template<class _UIntType, int __w, int __n, int __m, int __r,
_UInt a, int u, int s, _UIntType __a, int __u, int __s,
_UInt b, int t, _UInt c, int l> _UIntType __b, int __t, _UIntType __c, int __l>
void void
mersenne_twister<_UInt, w, n, m, r, a, u, s, b, t, c, l>:: mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s,
seed(unsigned long value) __b, __t, __c, __l>::
seed(unsigned long __value)
{ {
_M_x[0] = _Private::mod_w<_UInt, w>(value); _M_x[0] = _Private::__mod_w<_UIntType, __w>(__value);
for (int i = 1; i < n; ++i) for (int __i = 1; __i < state_size; ++__i)
{ {
_UInt x = _M_x[i - 1]; _UIntType __x = _M_x[__i - 1];
x ^= x >> (w - 2); __x ^= __x >> (__w - 2);
x *= 1812433253ul; __x *= 1812433253ul;
x += i; __x += __i;
_M_x[i] = _Private::mod_w<_UInt, w>(x); _M_x[__i] = _Private::__mod_w<_UIntType, __w>(__x);
} }
_M_p = n; _M_p = state_size;
} }
template<class _UInt, int w, int n, int m, int r, template<class _UIntType, int __w, int __n, int __m, int __r,
_UInt a, int u, int s, _UIntType __a, int __u, int __s,
_UInt b, int t, _UInt c, int l> _UIntType __b, int __t, _UIntType __c, int __l>
template<class Gen> template<class _Gen>
void void
mersenne_twister<_UInt, w, n, m, r, a, u, s, b, t, c, l>:: mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s,
seed(Gen& gen, false_type) __b, __t, __c, __l>::
seed(_Gen& __gen, false_type)
{ {
for (int i = 0; i < n; ++i) for (int __i = 0; __i < state_size; ++__i)
_M_x[i] = _Private::mod_w<_UInt, w>(gen()); _M_x[__i] = _Private::__mod_w<_UIntType, __w>(__gen());
_M_p = n; _M_p = state_size;
} }
template<class _UInt, int w, int n, int m, int r, template<class _UIntType, int __w, int __n, int __m, int __r,
_UInt a, int u, int s, _UIntType __a, int __u, int __s,
_UInt b, int t, _UInt c, int l> _UIntType __b, int __t, _UIntType __c, int __l>
typename typename
mersenne_twister<_UInt, w, n, m, r, a, u, s, b, t, c, l>::result_type mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s,
mersenne_twister<_UInt, w, n, m, r, a, u, s, b, t, c, l>:: __b, __t, __c, __l>::result_type
mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s,
__b, __t, __c, __l>::
max() const max() const
{ {
using _Private::Max_w; using _Private::_Max_w;
using std::numeric_limits; using std::numeric_limits;
return Max_w<_UInt, w, w == numeric_limits<_UInt>::digits>::value(); return _Max_w<_UIntType, __w,
__w == numeric_limits<_UIntType>::digits>::__value();
} }
template<class _UInt, int w, int n, int m, int r, template<class _UIntType, int __w, int __n, int __m, int __r,
_UInt a, int u, int s, _UIntType __a, int __u, int __s,
_UInt b, int t, _UInt c, int l> _UIntType __b, int __t, _UIntType __c, int __l>
typename typename
mersenne_twister<_UInt, w, n, m, r, a, u, s, b, t, c, l>::result_type mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s,
mersenne_twister<_UInt, w, n, m, r, a, u, s, b, t, c, l>:: __b, __t, __c, __l>::result_type
mersenne_twister<_UIntType, __w, __n, __m, __r, __a, __u, __s,
__b, __t, __c, __l>::
operator()() operator()()
{ {
// Reload the vector - cost is O(n) amortized over n calls. // Reload the vector - cost is O(n) amortized over n calls.
if (_M_p >= n) if (_M_p >= state_size)
{ {
const _UInt upper_mask = (~_UInt()) << r; const _UIntType __upper_mask = (~_UIntType()) << __r;
const _UInt lower_mask = ~upper_mask; const _UIntType __lower_mask = ~__upper_mask;
for (int k = 0; k < (n - m); ++k) for (int __k = 0; __k < (__n - __m); ++__k)
{ {
_UInt y = (_M_x[k] & upper_mask) | (_M_x[k + 1] & lower_mask); _UIntType __y = ((_M_x[__k] & __upper_mask)
_M_x[k] = _M_x[k + m] ^ (y >> 1) ^ ((y & 0x01) ? a : 0); |(_M_x[__k + 1] & __lower_mask));
_M_x[__k] = (_M_x[__k + __m] ^ (__y >> 1)
^ ((__y & 0x01) ? __a : 0));
} }
for (int k = (n - m); k < (n - 1); ++k) for (int __k = (__n - __m); __k < (__n - 1); ++__k)
{ {
_UInt y = (_M_x[k] & upper_mask) | (_M_x[k + 1] & lower_mask); _UIntType __y = ((_M_x[__k] & __upper_mask)
_M_x[k] = _M_x[k + (m - n)] ^ (y >> 1) ^ ((y & 0x01) ? a : 0); | (_M_x[__k + 1] & __lower_mask));
_M_x[__k] = (_M_x[__k + (__m - __n)] ^ (__y >> 1)
^ ((__y & 0x01) ? __a : 0));
} }
_M_p = 0; _M_p = 0;
} }
// Calculate o(x(i)). // Calculate o(x(i)).
result_type z = _M_x[_M_p++]; result_type __z = _M_x[_M_p++];
z ^= (z >> u); __z ^= (__z >> __u);
z ^= (z << s) & b; __z ^= (__z << __s) & __b;
z ^= (z << t) & c; __z ^= (__z << __t) & __c;
z ^= (z >> l); __z ^= (__z >> __l);
return z; return __z;
} }
template<typename _IntType, _IntType m, int s, int r> template<typename _IntType, _IntType __m, int __s, int __r>
void void
subtract_with_carry<_IntType, m, s, r>:: subtract_with_carry<_IntType, __m, __s, __r>::
seed(_IntType __value) seed(unsigned long __value)
{ {
std::tr1::linear_congruential<unsigned long, 40014, 0, 2147483563> std::tr1::linear_congruential<unsigned long, 40014, 0, 2147483563>
lcg(__value); __lcg(__value);
for (int i = 0; i < long_lag; ++i) for (int __i = 0; __i < long_lag; ++__i)
_M_x[i] = _Private::mod<_IntType, 1, 0, modulus>(lcg()); _M_x[__i] = _Private::__mod<_IntType, 1, 0, modulus>(__lcg());
_M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0; _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
_M_p = 0; _M_p = 0;
...@@ -337,22 +349,22 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -337,22 +349,22 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
// center. // center.
// //
template<typename _IntType, _IntType __m, int __s, int __r> template<typename _IntType, _IntType __m, int __s, int __r>
template<class Gen> template<class _Gen>
void void
subtract_with_carry<_IntType, __m, __s, __r>:: subtract_with_carry<_IntType, __m, __s, __r>::
seed(Gen& gen, false_type) seed(_Gen& __gen, false_type)
{ {
const int n = (std::numeric_limits<_IntType>::digits + 31) / 32; const int __n = (std::numeric_limits<_IntType>::digits + 31) / 32;
for (int i = 0; i < long_lag; ++i) for (int __i = 0; __i < long_lag; ++__i)
{ {
_M_x[i] = 0; _M_x[__i] = 0;
unsigned long factor = 1; unsigned long __factor = 1;
for (int j = 0; j < n; ++j) for (int __j = 0; __j < __n; ++__j)
{ {
_M_x[i] += gen() * factor; _M_x[__i] += __gen() * __factor;
factor *= 0x80000000; __factor *= 0x80000000;
} }
_M_x[i] = _Private::mod<_IntType, 1, 0, modulus>(_M_x[i]); _M_x[__i] = _Private::__mod<_IntType, 1, 0, modulus>(_M_x[__i]);
} }
_M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0; _M_carry = (_M_x[long_lag - 1] == 0) ? 1 : 0;
_M_p = 0; _M_p = 0;
...@@ -364,35 +376,36 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) ...@@ -364,35 +376,36 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
operator()() operator()()
{ {
// Derive short lag index from current index. // Derive short lag index from current index.
int ps = _M_p - short_lag; int __ps = _M_p - short_lag;
if (ps < 0) if (__ps < 0)
ps += long_lag; __ps += long_lag;
// Calculate new x(i) without overflow or division. // Calculate new x(i) without overflow or division.
_IntType xi; _IntType __xi;
if (_M_x[ps] >= _M_x[_M_p] + _M_carry) if (_M_x[__ps] >= _M_x[_M_p] + _M_carry)
{ {
xi = _M_x[ps] - _M_x[_M_p] - _M_carry; __xi = _M_x[__ps] - _M_x[_M_p] - _M_carry;
_M_carry = 0; _M_carry = 0;
} }
else else
{ {
xi = modulus - _M_x[_M_p] - _M_carry + _M_x[ps]; __xi = modulus - _M_x[_M_p] - _M_carry + _M_x[__ps];
_M_carry = 1; _M_carry = 1;
} }
_M_x[_M_p++] = xi; _M_x[_M_p++] = __xi;
// Adjust current index to loop around in ring buffer. // Adjust current index to loop around in ring buffer.
if (_M_p >= long_lag) if (_M_p >= long_lag)
_M_p = 0; _M_p = 0;
return xi; return __xi;
} }
template<class _E, int __p, int __r> template<class _UniformRandomNumberGenerator, int __p, int __r>
typename discard_block<_E, __p, __r>::result_type typename discard_block<_UniformRandomNumberGenerator,
discard_block<_E, __p, __r>:: __p, __r>::result_type
discard_block<_UniformRandomNumberGenerator, __p, __r>::
operator()() operator()()
{ {
if (_M_n >= used_block) if (_M_n >= used_block)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment