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();
205 virtual void PrintSelf(std::ostream & os,
Indent indent)
const
207 Superclass::PrintSelf(os, indent);
210 os << indent <<
"State vector: " << state << std::endl;
213 register int i = StateVectorLength;
214 for (; i--; os << *s++ <<
"\t" ) {}
218 os << indent <<
"Next value to be gotten from state: " << pNext << std::endl;
221 os << indent <<
"Values left before next reload: " << left << std::endl;
225 itkStaticConstMacro (M,
unsigned int, 397);
241 return hiBit(u) | loBits(v);
246 return m ^ ( mixBits(s0, s1) >> 1 ) ^ ( -loBit(s1) & 0x9908b0dfUL );
249 static IntegerType hash(vcl_time_t t, vcl_clock_t c);
266 unsigned char *p = (
unsigned char *)&t;
268 const unsigned int sizeOfT =
static_cast< unsigned int >(
sizeof(t) );
269 for (
unsigned int i = 0; i < sizeOfT; ++i )
271 h1 *= UCHAR_MAX + 2U;
275 p = (
unsigned char *)&c;
277 const unsigned int sizeOfC =
static_cast< unsigned int >(
sizeof(c) );
278 for (
unsigned int j = 0; j < sizeOfC; ++j )
280 h2 *= UCHAR_MAX + 2U;
283 return ( h1 + differ++ ) ^ h2;
298 *s++ = seed & 0xffffffffUL;
301 *s++ = ( 1812433253UL * ( *r ^ ( *r >> 30 ) ) + i ) & 0xffffffffUL;
314 register int index =
static_cast< int >(
322 *p =
twist(p[
M], p[0], p[1]);
324 for ( i =
M; --i; ++p )
326 *p =
twist(p[index], p[0], p[1]);
417 s1 ^= ( s1 << 7 ) & 0x9d2c5680UL;
418 s1 ^= ( s1 << 15 ) & 0xefc60000UL;
419 return ( s1 ^ ( s1 >> 18 ) );
498 return ( a * 67108864.0 + b ) * ( 1.0 / 9007199254740992.0 );
506 const double & mean,
const double & variance)
514 return mean + r *vcl_cos(phi);
521 const double & a,
const double & b)
525 return ( ( 1.0 - u ) * a + u * b );