52 #ifndef __PCL_Random_h
53 #define __PCL_Random_h
58 #include <pcl/Diagnostics.h>
106 return seed.u32[0] ^ seed.u32[1];
111 class FastMersenneTwister;
183 return m_rmax*Rand32();
214 double Normal(
double mean = 0,
double sigma = 1 );
222 double Gaussian(
double mean = 0,
double sigma = 1 )
224 return Normal( mean, sigma );
246 PCL_PRECONDITION( ymax > 0 )
247 PCL_PRECONDITION( 1 + ymax != 1 )
248 m_rmax = (m_ymax = ymax)/
double(
uint32_max );
317 double operator ()() noexcept
319 return 5.4210108624275221703311e-20 * UI64();
328 uint64 s1 = m_s[m_p = (m_p + 1) & 15];
332 return (m_s[m_p] = s0 ^ s1) * 1181783497276652981ull;
379 for (
int i = 0; i < 16; ++i )
384 m_s[i] = x * 2685821657736338717ull;
418 return (x << k) | (x >> (64 - k));
428 uint64 z = (x += 0x9e3779b97f4a7c15);
429 z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
430 z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
431 return z ^ (z >> 31);
440 static double UI64ToDouble(
uint64 x ) noexcept
442 return (x >> 11) * 0x1.0p-53;
496 double operator ()() noexcept
498 return UI64ToDouble( UI64() );
506 const uint64 result =
RotL( m_s[1]*5, 7 ) * 9;
507 const uint64 t = m_s[1] << 17;
513 m_s[3] =
RotL( m_s[3], 45 );
561 for (
int i = 0; i < 4; ++i )
562 m_s[i] = SplitMix64( x );
620 double operator ()() noexcept
622 return UI64ToDouble( UI64() );
631 const uint64 s0 = m_s[m_p = (m_p + 1) & 15];
635 m_s[q] =
RotL( s0, 25 ) ^ s15 ^ (s15 << 27);
636 m_s[m_p] =
RotL( s15, 36 );
684 for (
int i = 0; i < 16; ++i )
685 m_s[i] = SplitMix64( x );
720 double operator ()() noexcept
734 m_s = m_v1*m_v1 + m_v2*m_v2;
736 while ( m_s >= 1 || m_s <= std::numeric_limits<double>::epsilon() );
738 x = m_v1 *
Sqrt( -2*
Ln( m_s )/m_s );
741 x = m_v2 *
Sqrt( -2*
Ln( m_s )/m_s );
780 int operator ()(
double value ) noexcept
789 double p = 1, L =
Exp( -value );
811 double c = 0.767 - 3.36/value;
813 double alpha = beta*value;
814 double k =
Ln( c ) - value -
Ln( beta );
818 double x = (alpha -
Ln( (1 - u)/u ))/beta;
819 int n = int(
Floor( x + 0.5 ) );
823 double y = alpha - beta*x;
824 double temp = 1 +
Exp( y );
825 double lhs = y +
Ln( v/temp/temp );
860 throw Error(
"GammaRandomDeviates(): The function shape parameter must be > 0." );
862 throw Error(
"GammaRandomDeviates(): The scale parameter must be > 0." );
864 m_d = ((m_shape >= 1) ? m_shape : m_shape + 1) - 1.0/3.0;
865 m_c = 1/
Sqrt( 9*m_d );
872 double operator ()() noexcept
893 double xsquared = x*x;
894 if ( u < 1 - 0.0331*xsquared*xsquared ||
Ln( u ) < 0.5*xsquared + m_d*(1 - v +
Ln( v )) )
896 double g = m_scale*m_d*v;
898 g *=
Pow( m_R(), 1/m_shape );
A simple exception with an associated error message.
Generation of random gamma deviates.
GammaRandomDeviates(RNG &R, double shape=1, double scale=1) noexcept(false)
Generic vector of arbitrary length.
Generation of random normal (Gaussian) deviates.
NormalRandomDeviates(RNG &R) noexcept(false)
Generation of random Poisson deviates.
PoissonRandomDeviates(RNG &R) noexcept(false)
Mersenne Twister (MT19937) pseudo-random number generator.
double UpperBound() const
int Poisson(double lambda)
double Normal(double mean=0, double sigma=1)
double Gaussian(double mean=0, double sigma=1)
RandomNumberGenerator(double ymax=1.0, uint32 seed=0)
virtual ~RandomNumberGenerator()
void SetUpperBound(double ymax)
Implementation of the xoroshiro1024** pseudo-random number generator.
void Initialize(uint64 x)
uint32 UI32N(uint32 n) noexcept
uint64 UI64N(uint64 n) noexcept
uint32 UIN(uint32 n) noexcept
XoRoShiRo1024ss(uint64 seed=0) noexcept(false)
Implementation of the xoshiro256** pseudo-random number generator.
XoShiRo256ss(uint64 seed=0) noexcept(false)
uint32 UI32N(uint32 n) noexcept
uint64 UI64N(uint64 n) noexcept
uint32 UIN(uint32 n) noexcept
void Initialize(uint64 x)
Base class of xoshiro and xoroshiro pseudo-random number generators.
Implementation of the XorShift1024* pseudo-random number generator.
uint32 UIN(uint32 n) noexcept
void Initialize(uint64 x)
uint64 UI64N(uint64 n) noexcept
XorShift1024(uint64 seed=0) noexcept(false)
uint32 UI32N(uint32 n) noexcept
Complex< T1 > Pow(const Complex< T1 > &c, T2 x) noexcept
Complex< T > Sqrt(const Complex< T > &c) noexcept
Complex< T > Exp(const Complex< T > &c) noexcept
Complex< T > Ln(const Complex< T > &c) noexcept
T RotL(T x, uint32 n) noexcept
double LnFactorial(int n) noexcept
constexpr T Floor(T x) noexcept
unsigned long long uint64