18 #ifndef __itkMersenneTwisterRandomVariateGenerator_h
19 #define __itkMersenneTwisterRandomVariateGenerator_h
25 #include "vcl_ctime.h"
26 #include "vnl/vnl_math.h"
144 double GetVariateWithClosedRange();
147 double GetVariateWithClosedRange(
const double & n);
150 double GetVariateWithOpenUpperRange();
153 double GetVariateWithOpenUpperRange(
const double & n);
156 double GetVariateWithOpenRange();
159 double GetVariateWithOpenRange(
const double & n);
169 double Get53BitVariate();
173 double GetNormalVariate(
const double & mean = 0.0,
174 const double & variance = 1.0);
178 double GetUniformVariate(
const double & a,
const double & b);
185 virtual double GetVariate();
193 inline void SetSeed();
206 virtual void PrintSelf(std::ostream & os,
Indent indent)
const
208 Superclass::PrintSelf(os, indent);
211 os << indent <<
"State vector: " << state << std::endl;
214 register int i = StateVectorLength;
215 for (; i--; os << *s++ <<
"\t" ) {}
219 os << indent <<
"Next value to be gotten from state: " << pNext << std::endl;
222 os << indent <<
"Values left before next reload: " << left << std::endl;
226 itkStaticConstMacro (M,
unsigned int, 397);
242 return hiBit(u) | loBits(v);
247 return m ^ ( mixBits(s0, s1) >> 1 ) ^ ( -loBit(s1) & 0x9908b0df );
250 static IntegerType hash(vcl_time_t t, vcl_clock_t c);
267 unsigned char *p = (
unsigned char *)&t;
269 const unsigned int sizeOfT =
static_cast< unsigned int >(
sizeof(t) );
270 for (
unsigned int i = 0; i < sizeOfT; ++i )
272 h1 *= UCHAR_MAX + 2U;
276 p = (
unsigned char *)&c;
278 const unsigned int sizeOfC =
static_cast< unsigned int >(
sizeof(c) );
279 for (
unsigned int j = 0; j < sizeOfC; ++j )
281 h2 *= UCHAR_MAX + 2U;
284 return ( h1 + differ++ ) ^ h2;
299 *s++ = seed & 0xffffffffUL;
302 *s++ = ( 1812433253UL * ( *r ^ ( *r >> 30 ) ) + i ) & 0xffffffffUL;
315 register int index =
static_cast< int >(
323 *p =
twist(p[
M], p[0], p[1]);
325 for ( i =
M; --i; ++p )
327 *p =
twist(p[index], p[0], p[1]);
418 s1 ^= ( s1 << 7 ) & 0x9d2c5680;
419 s1 ^= ( s1 << 15 ) & 0xefc60000;
420 return ( s1 ^ ( s1 >> 18 ) );
499 return ( a * 67108864.0 + b ) * ( 1.0 / 9007199254740992.0 );
507 const double & mean,
const double & variance)
515 return mean + r *vcl_cos(phi);
522 const double & a,
const double & b)
526 return ( ( 1.0 - u ) * a + u * b );