GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
randmtzig.cc File Reference
#include <cmath>
#include <cstdio>
#include <ctime>
#include <algorithm>
#include <random>
#include "oct-syscalls.h"
#include "oct-time.h"
#include "randmtzig.h"

Go to the source code of this file.

Macros

#define EMANTISSA   9007199254740992.0 /* 53 bit mantissa */
 
#define EMANTISSA   4294967296.0 /* 32 bit mantissa */
 
#define ERANDI   randi53() /* 53 bits for mantissa */
 
#define ERANDI   randi32() /* 32 bits for mantissa */
 
#define EXP_SECTION_AREA   0.0039496598225815571993
 
#define LMASK   0x7fffffffUL /* least significant r bits */
 
#define MATRIX_A   0x9908b0dfUL /* constant vector a */
 
#define MIXBITS(u, v)   ( ((u) & UMASK) | ((v) & LMASK) )
 
#define MT_M   397
 
#define NMANTISSA   EMANTISSA
 
#define NMANTISSA   2147483648.0 /* 31 bit mantissa */
 
#define NOR_SECTION_AREA   0.00492867323399
 
#define NRANDI   randi54() /* 53 bits for mantissa + 1 bit sign */
 
#define NRANDI   randi32() /* 31 bits for mantissa + 1 bit sign */
 
#define randi32   randmt
 
#define RANDU   randu53()
 
#define RANDU   randu24()
 
#define TWIST(u, v)   ((MIXBITS(u,v) >> 1) ^ ((v)&1UL ? MATRIX_A : 0UL))
 
#define UMASK   0x80000000UL /* most significant w-r bits */
 
#define USE_X86_32   0
 
#define ZIGGURAT_EXP_INV_R   0.129918765548341586
 
#define ZIGGURAT_EXP_R   7.69711747013104972
 
#define ZIGGURAT_NOR_INV_R   0.27366123732975828
 
#define ZIGGURAT_NOR_R   3.6541528853610088
 
#define ZIGGURAT_TABLE_SIZE   256
 
#define ZIGINT   uint64_t
 
#define ZIGINT   uint32_t
 

Functions

void create_ziggurat_tables ()
 
void get_mersenne_twister_state (uint32_t *save)
 
void init_mersenne_twister ()
 
void init_mersenne_twister (const uint32_t *init_key, const int key_length)
 
void init_mersenne_twister (const uint32_t s)
 
template<>
void rand_exponential (octave_idx_type n, double *p)
 
template<>
void rand_exponential (octave_idx_type n, float *p)
 
template<>
double rand_exponential< double > ()
 
template<>
float rand_exponential< float > ()
 
template<>
void rand_normal (octave_idx_type n, double *p)
 
template<>
void rand_normal (octave_idx_type n, float *p)
 
template<>
double rand_normal< double > ()
 
template<>
float rand_normal< float > ()
 
template<>
void rand_uniform (octave_idx_type n, float *p)
 
template<>
double rand_uniform< double > ()
 
template<>
void rand_uniform< double > (octave_idx_type n, double *p)
 
template<>
float rand_uniform< float > ()
 
void set_mersenne_twister_state (const uint32_t *save)
 

Macro Definition Documentation

◆ EMANTISSA [1/2]

#define EMANTISSA   9007199254740992.0 /* 53 bit mantissa */

Definition at line 714 of file randmtzig.cc.

◆ EMANTISSA [2/2]

#define EMANTISSA   4294967296.0 /* 32 bit mantissa */

Definition at line 714 of file randmtzig.cc.

◆ ERANDI [1/2]

#define ERANDI   randi53() /* 53 bits for mantissa */

Definition at line 715 of file randmtzig.cc.

◆ ERANDI [2/2]

#define ERANDI   randi32() /* 32 bits for mantissa */

Definition at line 715 of file randmtzig.cc.

◆ EXP_SECTION_AREA

#define EXP_SECTION_AREA   0.0039496598225815571993

Definition at line 465 of file randmtzig.cc.

◆ LMASK

#define LMASK   0x7fffffffUL /* least significant r bits */

Definition at line 188 of file randmtzig.cc.

◆ MATRIX_A

#define MATRIX_A   0x9908b0dfUL /* constant vector a */

Definition at line 186 of file randmtzig.cc.

◆ MIXBITS

#define MIXBITS (   u,
 
)    ( ((u) & UMASK) | ((v) & LMASK) )

Definition at line 189 of file randmtzig.cc.

◆ MT_M

#define MT_M   397

Definition at line 185 of file randmtzig.cc.

◆ NMANTISSA [1/2]

#define NMANTISSA   EMANTISSA

Definition at line 716 of file randmtzig.cc.

◆ NMANTISSA [2/2]

#define NMANTISSA   2147483648.0 /* 31 bit mantissa */

Definition at line 716 of file randmtzig.cc.

◆ NOR_SECTION_AREA

#define NOR_SECTION_AREA   0.00492867323399

Definition at line 461 of file randmtzig.cc.

◆ NRANDI [1/2]

#define NRANDI   randi54() /* 53 bits for mantissa + 1 bit sign */

Definition at line 717 of file randmtzig.cc.

◆ NRANDI [2/2]

#define NRANDI   randi32() /* 31 bits for mantissa + 1 bit sign */

Definition at line 717 of file randmtzig.cc.

◆ randi32

#define randi32   randmt

Definition at line 374 of file randmtzig.cc.

◆ RANDU [1/2]

#define RANDU   randu53()

Definition at line 718 of file randmtzig.cc.

◆ RANDU [2/2]

#define RANDU   randu24()

Definition at line 718 of file randmtzig.cc.

◆ TWIST

#define TWIST (   u,
 
)    ((MIXBITS(u,v) >> 1) ^ ((v)&1UL ? MATRIX_A : 0UL))

Definition at line 190 of file randmtzig.cc.

◆ UMASK

#define UMASK   0x80000000UL /* most significant w-r bits */

Definition at line 187 of file randmtzig.cc.

◆ USE_X86_32

#define USE_X86_32   0

Definition at line 177 of file randmtzig.cc.

◆ ZIGGURAT_EXP_INV_R

#define ZIGGURAT_EXP_INV_R   0.129918765548341586

Definition at line 464 of file randmtzig.cc.

◆ ZIGGURAT_EXP_R

#define ZIGGURAT_EXP_R   7.69711747013104972

Definition at line 463 of file randmtzig.cc.

◆ ZIGGURAT_NOR_INV_R

#define ZIGGURAT_NOR_INV_R   0.27366123732975828

Definition at line 460 of file randmtzig.cc.

◆ ZIGGURAT_NOR_R

#define ZIGGURAT_NOR_R   3.6541528853610088

Definition at line 459 of file randmtzig.cc.

◆ ZIGGURAT_TABLE_SIZE

#define ZIGGURAT_TABLE_SIZE   256

Definition at line 457 of file randmtzig.cc.

◆ ZIGINT [1/2]

#define ZIGINT   uint64_t

Definition at line 713 of file randmtzig.cc.

◆ ZIGINT [2/2]

#define ZIGINT   uint32_t

Definition at line 713 of file randmtzig.cc.

Function Documentation

◆ create_ziggurat_tables()

void create_ziggurat_tables ( )

Definition at line 518 of file randmtzig.cc.

References x, and ZIGGURAT_NOR_R.

◆ get_mersenne_twister_state()

void get_mersenne_twister_state ( uint32_t *  save)

Definition at line 323 of file randmtzig.cc.

◆ init_mersenne_twister() [1/3]

void init_mersenne_twister ( )

Definition at line 263 of file randmtzig.cc.

References getpid(), init_mersenne_twister(), min(), MT_N, and n.

◆ init_mersenne_twister() [2/3]

void init_mersenne_twister ( const uint32_t *  init_key,
const int  key_length 
)

Definition at line 222 of file randmtzig.cc.

References init_mersenne_twister(), and MT_N.

◆ init_mersenne_twister() [3/3]

void init_mersenne_twister ( const uint32_t  s)

Definition at line 201 of file randmtzig.cc.

Referenced by init_mersenne_twister().

◆ rand_exponential() [1/2]

template<>
void rand_exponential ( octave_idx_type  n,
double *  p 
)

Definition at line 701 of file randmtzig.cc.

References n, and rand_exponential< double >().

◆ rand_exponential() [2/2]

template<>
void rand_exponential ( octave_idx_type  n,
float *  p 
)

Definition at line 884 of file randmtzig.cc.

References n, and rand_exponential< float >().

◆ rand_exponential< double >()

template<>
double rand_exponential< double > ( )

Definition at line 664 of file randmtzig.cc.

Referenced by rand_exponential().

◆ rand_exponential< float >()

template<>
float rand_exponential< float > ( )

Definition at line 847 of file randmtzig.cc.

Referenced by rand_exponential().

◆ rand_normal() [1/2]

template<>
void rand_normal ( octave_idx_type  n,
double *  p 
)

Definition at line 696 of file randmtzig.cc.

References n, and rand_normal< double >().

◆ rand_normal() [2/2]

template<>
void rand_normal ( octave_idx_type  n,
float *  p 
)

Definition at line 879 of file randmtzig.cc.

References n, and rand_normal< float >().

◆ rand_normal< double >()

template<>
double rand_normal< double > ( )

Definition at line 598 of file randmtzig.cc.

Referenced by rand_normal().

◆ rand_normal< float >()

template<>
float rand_normal< float > ( )

Definition at line 805 of file randmtzig.cc.

Referenced by rand_normal().

◆ rand_uniform()

template<>
void rand_uniform ( octave_idx_type  n,
float *  p 
)

Definition at line 874 of file randmtzig.cc.

References n, and rand_uniform< float >().

◆ rand_uniform< double >() [1/2]

template<>
double rand_uniform< double > ( )

Definition at line 441 of file randmtzig.cc.

Referenced by rand_uniform< double >().

◆ rand_uniform< double >() [2/2]

template<>
void rand_uniform< double > ( octave_idx_type  n,
double *  p 
)

Definition at line 691 of file randmtzig.cc.

References n, and rand_uniform< double >().

◆ rand_uniform< float >()

template<>
float rand_uniform< float > ( )

Definition at line 449 of file randmtzig.cc.

Referenced by rand_uniform().

◆ set_mersenne_twister_state()

void set_mersenne_twister_state ( const uint32_t *  save)

Definition at line 315 of file randmtzig.cc.

References MT_N.