GNU Octave  8.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"
Include dependency graph for randmtzig.cc:

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

static void create_ziggurat_float_tables (void)
 
void create_ziggurat_tables (void)
 
void get_mersenne_twister_state (uint32_t *save)
 
void init_mersenne_twister (const uint32_t *init_key, const int key_length)
 
void init_mersenne_twister (const uint32_t s)
 
void init_mersenne_twister (void)
 
static void next_state (void)
 
template<>
OCTAVE_API void rand_exponential (octave_idx_type n, double *p)
 
template<>
OCTAVE_API void rand_exponential (octave_idx_type n, float *p)
 
template<>
OCTAVE_API double rand_exponential< double > (void)
 
template<>
OCTAVE_API float rand_exponential< float > (void)
 
template<>
OCTAVE_API void rand_normal (octave_idx_type n, double *p)
 
template<>
OCTAVE_API void rand_normal (octave_idx_type n, float *p)
 
template<>
OCTAVE_API double rand_normal< double > (void)
 
template<>
OCTAVE_API float rand_normal< float > (void)
 
template<>
OCTAVE_API void rand_uniform (octave_idx_type n, float *p)
 
template<>
OCTAVE_API void rand_uniform< double > (octave_idx_type n, double *p)
 
template<>
OCTAVE_API double rand_uniform< double > (void)
 
template<>
OCTAVE_API float rand_uniform< float > (void)
 
static uint64_t randi53 (void)
 
static uint64_t randi54 (void)
 
static uint32_t randmt (void)
 
static float randu24 (void)
 
static double randu53 (void)
 
void set_mersenne_twister_state (const uint32_t *save)
 

Variables

static double fe [256]
 
static float ffe [256]
 
static float ffi [256]
 
static double fi [256]
 
static uint32_t fke [256]
 
static uint32_t fki [256]
 
static float fwe [256]
 
static float fwi [256]
 
static int initf = 0
 
static int initt = 1
 
static int inittf = 1
 
static uint64_t ke [256]
 
static uint64_t ki [256]
 
static int left = 1
 
static uint32_t * next
 
static uint32_t state [624]
 
static double we [256]
 
static double wi [256]
 

Macro Definition Documentation

◆ EMANTISSA [1/2]

#define EMANTISSA   9007199254740992.0 /* 53 bit mantissa */

Definition at line 698 of file randmtzig.cc.

◆ EMANTISSA [2/2]

#define EMANTISSA   4294967296.0 /* 32 bit mantissa */

Definition at line 698 of file randmtzig.cc.

◆ ERANDI [1/2]

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

Definition at line 699 of file randmtzig.cc.

◆ ERANDI [2/2]

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

Definition at line 699 of file randmtzig.cc.

◆ EXP_SECTION_AREA

#define EXP_SECTION_AREA   0.0039496598225815571993

Definition at line 454 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 700 of file randmtzig.cc.

◆ NMANTISSA [2/2]

#define NMANTISSA   2147483648.0 /* 31 bit mantissa */

Definition at line 700 of file randmtzig.cc.

◆ NOR_SECTION_AREA

#define NOR_SECTION_AREA   0.00492867323399

Definition at line 450 of file randmtzig.cc.

◆ NRANDI [1/2]

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

Definition at line 701 of file randmtzig.cc.

◆ NRANDI [2/2]

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

Definition at line 701 of file randmtzig.cc.

◆ randi32

#define randi32   randmt

Definition at line 367 of file randmtzig.cc.

◆ RANDU [1/2]

#define RANDU   randu53()

Definition at line 702 of file randmtzig.cc.

◆ RANDU [2/2]

#define RANDU   randu24()

Definition at line 702 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 453 of file randmtzig.cc.

◆ ZIGGURAT_EXP_R

#define ZIGGURAT_EXP_R   7.69711747013104972

Definition at line 452 of file randmtzig.cc.

◆ ZIGGURAT_NOR_INV_R

#define ZIGGURAT_NOR_INV_R   0.27366123732975828

Definition at line 449 of file randmtzig.cc.

◆ ZIGGURAT_NOR_R

#define ZIGGURAT_NOR_R   3.6541528853610088

Definition at line 448 of file randmtzig.cc.

◆ ZIGGURAT_TABLE_SIZE

#define ZIGGURAT_TABLE_SIZE   256

Definition at line 446 of file randmtzig.cc.

◆ ZIGINT [1/2]

#define ZIGINT   uint64_t

Definition at line 697 of file randmtzig.cc.

◆ ZIGINT [2/2]

#define ZIGINT   uint32_t

Definition at line 697 of file randmtzig.cc.

Function Documentation

◆ create_ziggurat_float_tables()

static void create_ziggurat_float_tables ( void  )
static

◆ create_ziggurat_tables()

void create_ziggurat_tables ( void  )

◆ get_mersenne_twister_state()

void get_mersenne_twister_state ( uint32_t *  save)

Definition at line 318 of file randmtzig.cc.

References left, MT_N, and state.

Referenced by rand::get_internal_state().

◆ init_mersenne_twister() [1/3]

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

Definition at line 220 of file randmtzig.cc.

References init_mersenne_twister(), initf, left, MT_N, and state.

◆ init_mersenne_twister() [2/3]

void init_mersenne_twister ( const uint32_t  s)

◆ init_mersenne_twister() [3/3]

void init_mersenne_twister ( void  )

Definition at line 260 of file randmtzig.cc.

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

◆ next_state()

static void next_state ( void  )
static

Definition at line 324 of file randmtzig.cc.

References init_mersenne_twister(), initf, left, MT_M, MT_N, next, state, and TWIST.

Referenced by randmt().

◆ rand_exponential() [1/2]

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

Definition at line 685 of file randmtzig.cc.

References n, and rand_exponential< double >().

◆ rand_exponential() [2/2]

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

Definition at line 863 of file randmtzig.cc.

References n, and rand_exponential< float >().

◆ rand_exponential< double >()

template<>
OCTAVE_API double rand_exponential< double > ( void  )

Definition at line 649 of file randmtzig.cc.

References create_ziggurat_tables(), ERANDI, fe, initt, ke, RANDU, we, x, ZIGGURAT_EXP_R, and ZIGINT.

Referenced by rand::exponential(), rand::fill(), and rand_exponential().

◆ rand_exponential< float >()

template<>
OCTAVE_API float rand_exponential< float > ( void  )

◆ rand_normal() [1/2]

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

Definition at line 680 of file randmtzig.cc.

References n, and rand_normal< double >().

◆ rand_normal() [2/2]

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

Definition at line 858 of file randmtzig.cc.

References n, and rand_normal< float >().

◆ rand_normal< double >()

template<>
OCTAVE_API double rand_normal< double > ( void  )

◆ rand_normal< float >()

template<>
OCTAVE_API float rand_normal< float > ( void  )

◆ rand_uniform()

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

Definition at line 853 of file randmtzig.cc.

References n, and rand_uniform< float >().

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

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

Definition at line 675 of file randmtzig.cc.

References n, and rand_uniform< double >().

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

template<>
OCTAVE_API double rand_uniform< double > ( void  )

◆ rand_uniform< float >()

template<>
OCTAVE_API float rand_uniform< float > ( void  )

Definition at line 438 of file randmtzig.cc.

References randu24().

Referenced by rand::fill(), rand_uniform(), and rand::uniform().

◆ randi53()

static uint64_t randi53 ( void  )
static

Definition at line 369 of file randmtzig.cc.

References randi32.

◆ randi54()

static uint64_t randi54 ( void  )
static

Definition at line 384 of file randmtzig.cc.

References randi32.

◆ randmt()

static uint32_t randmt ( void  )
static

Definition at line 349 of file randmtzig.cc.

References left, next, and next_state().

◆ randu24()

static float randu24 ( void  )
static

Definition at line 400 of file randmtzig.cc.

References randi32.

Referenced by rand_uniform< float >().

◆ randu53()

static double randu53 ( void  )
static

Definition at line 414 of file randmtzig.cc.

References randi32.

Referenced by rand_uniform< double >().

◆ set_mersenne_twister_state()

void set_mersenne_twister_state ( const uint32_t *  save)

Definition at line 311 of file randmtzig.cc.

References left, MT_N, next, and state.

Referenced by rand::set_internal_state().

Variable Documentation

◆ fe

double fe[256]
static

◆ ffe

float ffe[256]
static

Definition at line 707 of file randmtzig.cc.

Referenced by create_ziggurat_float_tables(), and rand_exponential< float >().

◆ ffi

float ffi[256]
static

Definition at line 705 of file randmtzig.cc.

Referenced by create_ziggurat_float_tables(), and rand_normal< float >().

◆ fi

◆ fke

uint32_t fke[256]
static

Definition at line 706 of file randmtzig.cc.

Referenced by create_ziggurat_float_tables(), and rand_exponential< float >().

◆ fki

uint32_t fki[256]
static

Definition at line 704 of file randmtzig.cc.

Referenced by create_ziggurat_float_tables(), and rand_normal< float >().

◆ fwe

float fwe[256]
static

Definition at line 707 of file randmtzig.cc.

Referenced by create_ziggurat_float_tables(), and rand_exponential< float >().

◆ fwi

float fwi[256]
static

Definition at line 705 of file randmtzig.cc.

Referenced by create_ziggurat_float_tables(), and rand_normal< float >().

◆ initf

int initf = 0
static

Definition at line 195 of file randmtzig.cc.

Referenced by init_mersenne_twister(), and next_state().

◆ initt

int initt = 1
static

◆ inittf

int inittf = 1
static

◆ ke

uint64_t ke[256]
static

Definition at line 465 of file randmtzig.cc.

Referenced by create_ziggurat_tables(), and rand_exponential< double >().

◆ ki

uint64_t ki[256]
static

Definition at line 463 of file randmtzig.cc.

Referenced by create_ziggurat_tables(), and rand_normal< double >().

◆ left

◆ next

◆ state

◆ we

double we[256]
static

◆ wi