157 #if defined (HAVE_CONFIG_H)
173 #if ! defined (USE_X86_32)
174 # if defined (i386) || defined (HAVE_X86_32)
175 # define USE_X86_32 1
177 # define USE_X86_32 0
186 #define MATRIX_A 0x9908b0dfUL
187 #define UMASK 0x80000000UL
188 #define LMASK 0x7fffffffUL
189 #define MIXBITS(u,v) ( ((u) & UMASK) | ((v) & LMASK) )
190 #define TWIST(u,v) ((MIXBITS(u,v) >> 1) ^ ((v)&1UL ? MATRIX_A : 0UL))
203 state[0] = s & 0xffffffffUL;
204 for (j = 1; j <
MT_N; j++)
211 state[j] &= 0xffffffffUL;
226 k = (
MT_N > key_length ?
MT_N : key_length);
231 state[i] &= 0xffffffffUL;
242 for (k =
MT_N - 1; k; k--)
246 state[i] &= 0xffffffffUL;
255 state[0] = 0x80000000UL;
262 uint32_t entropy[
MT_N];
271 entropy[
n++] = now.unix_time ();
275 entropy[
n++] = clock ();
279 entropy[
n++] = now.usec ();
294 std::random_device rd;
295 std::uniform_int_distribution<uint32_t> dist;
299 entropy[
n++] = dist (rd);
301 catch (
const std::exception&)
342 for (j =
MT_M; --j; p++)
359 y ^= (y << 7) & 0x9d2c5680UL;
360 y ^= (y << 15) & 0xefc60000UL;
361 return (y ^ (y >> 18));
367 #define randi32 randmt
371 const uint32_t lo =
randi32 ();
372 const uint32_t hi =
randi32 () & 0x1FFFFF;
373 #if defined (HAVE_X86_32)
375 uint32_t *p = (uint32_t *)&u;
380 return ((
static_cast<uint64_t
> (hi) << 32) | lo);
386 const uint32_t lo =
randi32 ();
387 const uint32_t hi =
randi32 () & 0x3FFFFF;
388 #if defined (HAVE_X86_32)
390 uint32_t *p =
static_cast<uint32_t *
> (&u);
395 return ((
static_cast<uint64_t
> (hi) << 32) | lo);
406 i =
randi32 () &
static_cast<uint32_t
> (0xFFFFFF);
410 return i * (1.0f / 16777216.0f);
423 while (a == 0 && b == 0);
425 return (a*67108864.0 + b) * (1.0/9007199254740992.0);
446 #define ZIGGURAT_TABLE_SIZE 256
448 #define ZIGGURAT_NOR_R 3.6541528853610088
449 #define ZIGGURAT_NOR_INV_R 0.27366123732975828
450 #define NOR_SECTION_AREA 0.00492867323399
452 #define ZIGGURAT_EXP_R 7.69711747013104972
453 #define ZIGGURAT_EXP_INV_R 0.129918765548341586
454 #define EXP_SECTION_AREA 0.0039496598225815571993
456 #define ZIGINT uint64_t
457 #define EMANTISSA 9007199254740992.0
458 #define ERANDI randi53()
459 #define NMANTISSA EMANTISSA
460 #define NRANDI randi54()
461 #define RANDU randu53()
514 fi[255] = exp (-0.5 * x1 * x1);
525 for (i = 254; i > 0; i--)
533 fi[i] = exp (-0.5 *
x *
x);
553 for (i = 254; i > 0; i--)
600 # if defined (HAVE_X86_32)
606 uint32_t *p = (uint32_t *)&rabs;
612 p[1] = hi & 0x1FFFFF;
613 x = ( si ? -rabs : rabs ) *
wi[idx];
617 const int64_t rabs =
r >> 1;
618 const int idx =
static_cast<int> (rabs & 0xFF);
619 const double x = ( (
r & 1) ? -rabs : rabs) *
wi[idx];
621 if (rabs <
static_cast<int64_t
> (
ki[idx]))
639 yy = - std::log (
RANDU);
641 while ( yy+yy <= xx*xx);
644 else if ((
fi[idx-1] -
fi[idx]) *
RANDU +
fi[idx] < exp (-0.5*
x*
x))
657 const int idx =
static_cast<int> (ri & 0xFF);
658 const double x = ri *
we[idx];
670 else if ((
fe[idx-1] -
fe[idx]) *
RANDU +
fe[idx] < exp (-
x))
697 #define ZIGINT uint32_t
698 #define EMANTISSA 4294967296.0
699 #define ERANDI randi32()
700 #define NMANTISSA 2147483648.0
701 #define NRANDI randi32()
702 #define RANDU randu24()
717 ffi[255] = exp (-0.5 * x1 * x1);
728 for (i = 254; i > 0; i--)
736 ffi[i] = exp (-0.5 *
x *
x);
745 ffe[255] = exp (-x1);
756 for (i = 254; i > 0; i--)
796 const uint32_t rabs =
r &
LMASK;
797 const int idx =
static_cast<int> (
r & 0xFF);
798 const float x =
static_cast<int32_t
> (
r) *
fwi[idx];
817 yy = - std::log (
RANDU);
819 while ( yy+yy <= xx*xx);
835 const int idx =
static_cast<int> (ri & 0xFF);
836 const float x = ri *
fwe[idx];
charNDArray min(char d, const charNDArray &m)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
F77_RET_T const F77_DBLE * x
void get_mersenne_twister_state(uint32_t *save)
void create_ziggurat_tables(void)
void set_mersenne_twister_state(const uint32_t *save)
#define ZIGGURAT_TABLE_SIZE
static void create_ziggurat_float_tables(void)
static double randu53(void)
static uint64_t randi53(void)
OCTAVE_API void rand_exponential(octave_idx_type n, double *p)
static void next_state(void)
OCTAVE_API double rand_uniform< double >(void)
void init_mersenne_twister(const uint32_t s)
static uint64_t randi54(void)
static uint32_t randmt(void)
OCTAVE_API float rand_exponential< float >(void)
static float randu24(void)
OCTAVE_API void rand_uniform(octave_idx_type n, float *p)
static uint32_t state[624]
OCTAVE_API float rand_normal< float >(void)
#define ZIGGURAT_NOR_INV_R
OCTAVE_API float rand_uniform< float >(void)
OCTAVE_API double rand_normal< double >(void)
OCTAVE_API double rand_exponential< double >(void)
OCTAVE_API void rand_normal(octave_idx_type n, double *p)