18 #ifndef itkMersenneTwisterRandomVariateGenerator_h
19 #define itkMersenneTwisterRandomVariateGenerator_h
123 struct MersenneTwisterGlobals;
172 double GetVariateWithClosedRange();
175 double GetVariateWithClosedRange(
const double & n);
178 double GetVariateWithOpenUpperRange();
181 double GetVariateWithOpenUpperRange(
const double & n);
184 double GetVariateWithOpenRange();
187 double GetVariateWithOpenRange(
const double & n);
197 double Get53BitVariate();
201 double GetNormalVariate(
const double & mean = 0.0,
202 const double & variance = 1.0);
206 double GetUniformVariate(
const double & a,
const double & b);
213 double GetVariate()
override;
223 inline void SetSeed();
248 void PrintSelf(std::ostream & os,
Indent indent)
const override;
251 static constexpr
unsigned int M = 397;
261 return hiBit(u) | loBits(v);
266 return m ^ ( mixBits(s0, s1) >> 1 ) ^ ( -static_cast<int32_t>(loBit(s1)) & 0x9908b0df );
269 static IntegerType hash(time_t t, clock_t c);
289 static Pointer CreateInstance();
315 *s++ = seed & 0xffffffffUL;
318 *s++ = ( 1812433253UL * ( *r ^ ( *r >> 30 ) ) + i ) & 0xffffffffUL;
332 auto index =
static_cast< int >(
340 *p =
twist(p[
M], p[0], p[1]);
342 for ( i =
M; --i; ++p )
344 *p =
twist(p[index], p[0], p[1]);
391 s1 ^= ( s1 << 7 ) & 0x9d2c5680;
392 s1 ^= ( s1 << 15 ) & 0xefc60000;
393 return ( s1 ^ ( s1 >> 18 ) );
471 return ( a * 67108864.0 + b ) * ( 1.0 / 9007199254740992.0 );
479 const double & mean,
const double & variance)
488 return mean + r *std::cos(phi);
495 const double & a,
const double & b)
499 return ( ( 1.0 - u ) * a + u * b );
double GetVariateWithOpenRange()
Light weight base class for most itk classes.
MersenneTwisterRandom random variate generator.
IntegerType GetIntegerVariate()
static constexpr double pi
IntegerType loBits(const IntegerType &u) const
IntegerType mixBits(const IntegerType &u, const IntegerType &v) const
double GetUniformVariate(const double &a, const double &b)
#define itkGetGlobalDeclarationMacro(Type, VarName)
double GetVariateWithClosedRange()
Defines common interfaces for random variate generators.
IntegerType state[StateVectorLength]
static constexpr unsigned int M
IntegerType twist(const IntegerType &m, const IntegerType &s0, const IntegerType &s1) const
double GetNormalVariate(const double &mean=0.0, const double &variance=1.0)
double GetVariate() override
std::mutex m_InstanceLock
static constexpr IntegerType StateVectorLength
static MersenneTwisterGlobals * m_PimplGlobals
Control indentation during Print() invocation.
IntegerType hiBit(const IntegerType &u) const
double GetVariateWithOpenUpperRange()
static IntegerType hash(time_t t, clock_t c)
IntegerType loBit(const IntegerType &u) const