157 #if defined (HAVE_CONFIG_H)
170 #if ! defined (USE_X86_32)
171 # if defined (i386) || defined (HAVE_X86_32)
172 # define USE_X86_32 1
174 # define USE_X86_32 0
183 #define MATRIX_A 0x9908b0dfUL
184 #define UMASK 0x80000000UL
185 #define LMASK 0x7fffffffUL
186 #define MIXBITS(u,v) ( ((u) & UMASK) | ((v) & LMASK) )
187 #define TWIST(u,v) ((MIXBITS(u,v) >> 1) ^ ((v)&1UL ? MATRIX_A : 0UL))
200 state[0] = s & 0xffffffffUL;
201 for (j = 1; j <
MT_N; j++)
208 state[j] &= 0xffffffffUL;
223 k = (
MT_N > key_length ?
MT_N : key_length);
228 state[i] &= 0xffffffffUL;
239 for (k =
MT_N - 1; k; k--)
243 state[i] &= 0xffffffffUL;
252 state[0] = 0x80000000UL;
259 uint32_t entropy[
MT_N];
263 FILE *urandom =
std::fopen (
"/dev/urandom",
"rb");
268 unsigned char word[4];
269 if (std::fread (word, 4, 1, urandom) != 1)
271 entropy[
n++] = word[0] + (word[1]<<8) + (word[2]<<16)
272 + (
static_cast<uint32_t
> (word[3])<<24);
274 std::fclose (urandom);
285 entropy[
n++] = clock ();
288 entropy[
n++] = now.
usec ();
325 for (j =
MT_M; --j; p++)
342 y ^= (y << 7) & 0x9d2c5680UL;
343 y ^= (y << 15) & 0xefc60000UL;
344 return (y ^ (y >> 18));
350 #define randi32 randmt
354 const uint32_t lo =
randi32 ();
355 const uint32_t hi =
randi32 () & 0x1FFFFF;
356 #if defined (HAVE_X86_32)
358 uint32_t *p = (uint32_t *)&u;
363 return ((
static_cast<uint64_t
> (hi) << 32) | lo);
369 const uint32_t lo =
randi32 ();
370 const uint32_t hi =
randi32 () & 0x3FFFFF;
371 #if defined (HAVE_X86_32)
373 uint32_t *p =
static_cast<uint32_t *
> (&u);
378 return ((
static_cast<uint64_t
> (hi) << 32) | lo);
389 i =
randi32 () &
static_cast<uint32_t
> (0xFFFFFF);
393 return i * (1.0f / 16777216.0f);
406 while (a == 0 && b == 0);
408 return (a*67108864.0 + b) * (1.0/9007199254740992.0);
429 #define ZIGGURAT_TABLE_SIZE 256
431 #define ZIGGURAT_NOR_R 3.6541528853610088
432 #define ZIGGURAT_NOR_INV_R 0.27366123732975828
433 #define NOR_SECTION_AREA 0.00492867323399
435 #define ZIGGURAT_EXP_R 7.69711747013104972
436 #define ZIGGURAT_EXP_INV_R 0.129918765548341586
437 #define EXP_SECTION_AREA 0.0039496598225815571993
439 #define ZIGINT uint64_t
440 #define EMANTISSA 9007199254740992.0
441 #define ERANDI randi53()
442 #define NMANTISSA EMANTISSA
443 #define NRANDI randi54()
444 #define RANDU randu53()
497 fi[255] = exp (-0.5 * x1 * x1);
508 for (i = 254; i > 0; i--)
516 fi[i] = exp (-0.5 *
x *
x);
536 for (i = 254; i > 0; i--)
583 # if defined (HAVE_X86_32)
589 uint32_t *p = (uint32_t *)&rabs;
595 p[1] = hi & 0x1FFFFF;
596 x = ( si ? -rabs : rabs ) *
wi[idx];
600 const int64_t rabs =
r >> 1;
601 const int idx =
static_cast<int> (rabs & 0xFF);
602 const double x = ( (
r & 1) ? -rabs : rabs) *
wi[idx];
604 if (rabs <
static_cast<int64_t
> (
ki[idx]))
622 yy = - std::log (
RANDU);
624 while ( yy+yy <= xx*xx);
627 else if ((
fi[idx-1] -
fi[idx]) *
RANDU +
fi[idx] < exp (-0.5*
x*
x))
640 const int idx =
static_cast<int> (ri & 0xFF);
641 const double x = ri *
we[idx];
653 else if ((
fe[idx-1] -
fe[idx]) *
RANDU +
fe[idx] < exp (-
x))
680 #define ZIGINT uint32_t
681 #define EMANTISSA 4294967296.0
682 #define ERANDI randi32()
683 #define NMANTISSA 2147483648.0
684 #define NRANDI randi32()
685 #define RANDU randu24()
700 ffi[255] = exp (-0.5 * x1 * x1);
711 for (i = 254; i > 0; i--)
719 ffi[i] = exp (-0.5 *
x *
x);
728 ffe[255] = exp (-x1);
739 for (i = 254; i > 0; i--)
779 const uint32_t rabs =
r &
LMASK;
780 const int idx =
static_cast<int> (
r & 0xFF);
781 const float x =
static_cast<int32_t
> (
r) *
fwi[idx];
800 yy = - std::log (
RANDU);
802 while ( yy+yy <= xx*xx);
818 const int idx =
static_cast<int> (ri & 0xFF);
819 const float x = ri *
fwe[idx];
time_t unix_time(void) const
F77_RET_T const F77_DBLE * x
std::FILE * fopen(const std::string &filename, const std::string &mode)
static uint64_t randi53(void)
static float randu24(void)
static uint32_t state[624]
double rand_normal< double >(void)
static uint32_t randmt(void)
static uint64_t randi54(void)
void set_mersenne_twister_state(const uint32_t *save)
static void create_ziggurat_float_tables(void)
float rand_normal< float >(void)
double rand_exponential< double >(void)
float rand_exponential< float >(void)
void init_mersenne_twister(const uint32_t s)
static void next_state(void)
float rand_uniform< float >(void)
void rand_exponential(octave_idx_type n, double *p)
void create_ziggurat_tables(void)
void rand_normal(octave_idx_type n, double *p)
void rand_uniform(octave_idx_type n, float *p)
void get_mersenne_twister_state(uint32_t *save)
double rand_uniform< double >(void)
static double randu53(void)
#define ZIGGURAT_TABLE_SIZE
#define ZIGGURAT_NOR_INV_R