#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 | |
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] |
#define EMANTISSA 9007199254740992.0 /* 53 bit mantissa */ |
Definition at line 698 of file randmtzig.cc.
#define EMANTISSA 4294967296.0 /* 32 bit mantissa */ |
Definition at line 698 of file randmtzig.cc.
Definition at line 699 of file randmtzig.cc.
Definition at line 699 of file randmtzig.cc.
#define EXP_SECTION_AREA 0.0039496598225815571993 |
Definition at line 454 of file randmtzig.cc.
#define LMASK 0x7fffffffUL /* least significant r bits */ |
Definition at line 188 of file randmtzig.cc.
#define MATRIX_A 0x9908b0dfUL /* constant vector a */ |
Definition at line 186 of file randmtzig.cc.
Definition at line 189 of file randmtzig.cc.
#define MT_M 397 |
Definition at line 185 of file randmtzig.cc.
#define NMANTISSA EMANTISSA |
Definition at line 700 of file randmtzig.cc.
#define NMANTISSA 2147483648.0 /* 31 bit mantissa */ |
Definition at line 700 of file randmtzig.cc.
#define NOR_SECTION_AREA 0.00492867323399 |
Definition at line 450 of file randmtzig.cc.
Definition at line 701 of file randmtzig.cc.
Definition at line 701 of file randmtzig.cc.
#define randi32 randmt |
Definition at line 367 of file randmtzig.cc.
#define RANDU randu53() |
Definition at line 702 of file randmtzig.cc.
#define RANDU randu24() |
Definition at line 702 of file randmtzig.cc.
Definition at line 190 of file randmtzig.cc.
#define UMASK 0x80000000UL /* most significant w-r bits */ |
Definition at line 187 of file randmtzig.cc.
#define USE_X86_32 0 |
Definition at line 177 of file randmtzig.cc.
#define ZIGGURAT_EXP_INV_R 0.129918765548341586 |
Definition at line 453 of file randmtzig.cc.
#define ZIGGURAT_EXP_R 7.69711747013104972 |
Definition at line 452 of file randmtzig.cc.
#define ZIGGURAT_NOR_INV_R 0.27366123732975828 |
Definition at line 449 of file randmtzig.cc.
#define ZIGGURAT_NOR_R 3.6541528853610088 |
Definition at line 448 of file randmtzig.cc.
#define ZIGGURAT_TABLE_SIZE 256 |
Definition at line 446 of file randmtzig.cc.
#define ZIGINT uint64_t |
Definition at line 697 of file randmtzig.cc.
#define ZIGINT uint32_t |
Definition at line 697 of file randmtzig.cc.
|
static |
Definition at line 709 of file randmtzig.cc.
References EMANTISSA, EXP_SECTION_AREA, ffe, ffi, fke, fki, fwe, fwi, inittf, NMANTISSA, NOR_SECTION_AREA, x, ZIGGURAT_EXP_R, ZIGGURAT_NOR_R, and ZIGINT.
Referenced by rand_exponential< float >(), and rand_normal< float >().
void create_ziggurat_tables | ( | void | ) |
Definition at line 506 of file randmtzig.cc.
References EMANTISSA, EXP_SECTION_AREA, fe, fi, initt, ke, ki, NMANTISSA, NOR_SECTION_AREA, we, wi, x, ZIGGURAT_EXP_R, ZIGGURAT_NOR_R, and ZIGINT.
Referenced by rand_exponential< double >(), and rand_normal< double >().
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().
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.
void init_mersenne_twister | ( | const uint32_t | s | ) |
Definition at line 200 of file randmtzig.cc.
References initf, left, MT_N, and state.
Referenced by rand::do_reset(), init_mersenne_twister(), rand::initialize_mersenne_twister(), next_state(), and rand::set_internal_state().
void init_mersenne_twister | ( | void | ) |
Definition at line 260 of file randmtzig.cc.
References getpid(), init_mersenne_twister(), min(), MT_N, and n.
|
static |
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 >().
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 >().
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().
OCTAVE_API float rand_exponential< float > | ( | void | ) |
Definition at line 827 of file randmtzig.cc.
References create_ziggurat_float_tables(), ERANDI, ffe, fke, fwe, inittf, RANDU, x, ZIGGURAT_EXP_R, and ZIGINT.
Referenced by rand::exponential(), rand::fill(), and rand_exponential().
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 >().
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 >().
OCTAVE_API double rand_normal< double > | ( | void | ) |
Definition at line 585 of file randmtzig.cc.
References create_ziggurat_tables(), fi, initt, ki, NRANDI, r, randi32, RANDU, UMASK, wi, x, ZIGGURAT_NOR_INV_R, and ZIGGURAT_NOR_R.
Referenced by rand::fill(), rand::normal(), and rand_normal().
OCTAVE_API float rand_normal< float > | ( | void | ) |
Definition at line 787 of file randmtzig.cc.
References create_ziggurat_float_tables(), ffi, fki, fwi, inittf, LMASK, r, randi32, RANDU, x, ZIGGURAT_NOR_INV_R, and ZIGGURAT_NOR_R.
Referenced by rand::fill(), rand::normal(), and rand_normal().
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 >().
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 >().
OCTAVE_API double rand_uniform< double > | ( | void | ) |
Definition at line 430 of file randmtzig.cc.
References randu53().
Referenced by rand::fill(), poisson_cdf_lookup(), poisson_rejection(), pprsc(), rand_uniform< double >(), and rand::uniform().
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().
|
static |
Definition at line 369 of file randmtzig.cc.
References randi32.
|
static |
Definition at line 384 of file randmtzig.cc.
References randi32.
|
static |
Definition at line 349 of file randmtzig.cc.
References left, next, and next_state().
|
static |
Definition at line 400 of file randmtzig.cc.
References randi32.
Referenced by rand_uniform< float >().
|
static |
Definition at line 414 of file randmtzig.cc.
References randi32.
Referenced by rand_uniform< double >().
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().
|
static |
Definition at line 466 of file randmtzig.cc.
Referenced by file_editor_tab_widget::file_editor_tab_widget(), create_ziggurat_tables(), and rand_exponential< double >().
|
static |
Definition at line 707 of file randmtzig.cc.
Referenced by create_ziggurat_float_tables(), and rand_exponential< float >().
|
static |
Definition at line 705 of file randmtzig.cc.
Referenced by create_ziggurat_float_tables(), and rand_normal< float >().
|
static |
Definition at line 464 of file randmtzig.cc.
Referenced by documentation::~documentation(), load_path::package_info::add_to_fcn_map(), load_path::package_info::add_to_method_map(), create_ziggurat_tables(), load_path::package_info::find_fcn(), load_path::package_info::find_method(), higham_subp(), load_path::file_info::operator=(), and rand_normal< double >().
|
static |
Definition at line 706 of file randmtzig.cc.
Referenced by create_ziggurat_float_tables(), and rand_exponential< float >().
|
static |
Definition at line 704 of file randmtzig.cc.
Referenced by create_ziggurat_float_tables(), and rand_normal< float >().
|
static |
Definition at line 707 of file randmtzig.cc.
Referenced by create_ziggurat_float_tables(), and rand_exponential< float >().
|
static |
Definition at line 705 of file randmtzig.cc.
Referenced by create_ziggurat_float_tables(), and rand_normal< float >().
|
static |
Definition at line 195 of file randmtzig.cc.
Referenced by init_mersenne_twister(), and next_state().
|
static |
Definition at line 196 of file randmtzig.cc.
Referenced by create_ziggurat_tables(), rand_exponential< double >(), and rand_normal< double >().
|
static |
Definition at line 197 of file randmtzig.cc.
Referenced by create_ziggurat_float_tables(), rand_exponential< float >(), and rand_normal< float >().
|
static |
Definition at line 465 of file randmtzig.cc.
Referenced by create_ziggurat_tables(), and rand_exponential< double >().
|
static |
Definition at line 463 of file randmtzig.cc.
Referenced by create_ziggurat_tables(), and rand_normal< double >().
|
static |
Definition at line 194 of file randmtzig.cc.
Referenced by symbol_info::display_line(), octave_perm_matrix::do_index_op(), octave_diag_matrix::do_index_op(), do_printf_string(), TerminalView::extendSelection(), Fcolloc(), get_mersenne_twister_state(), opengl_functions::glOrtho(), init_mersenne_twister(), idx_vector::is_permutation(), find_file_less_than::lessThan(), stream_list::list_open_files(), load_save_system::load_vars(), next_state(), find_file_less_than::operator()(), pr_scale_header(), print_DASPK_options(), print_DASRT_options(), print_DASSL_options(), symbol_info_list::print_descriptor(), print_LSODE_options(), print_Quad_options(), randmt(), set_mersenne_twister_state(), and Screen::writeSelectionToStream().
|
static |
Definition at line 192 of file randmtzig.cc.
Referenced by KeyboardTranslator::findEntry(), TerminalView::focusNextPrevChild(), octave_sort< T >::issorted(), next_state(), randmt(), textscan::read_until(), dw_main_window::request_switch(), and set_mersenne_twister_state().
|
static |
Definition at line 193 of file randmtzig.cc.
Referenced by TerminalModel::activityStateSet(), base_lexer::begin_string(), check_state(), ddaspk_f(), ddaspk_j(), ddasrt_f(), ddasrt_g(), ddasrt_j(), ddassl_f(), ddassl_j(), error_system::default_warning_state(), DEFMETHOD(), error_system::display_warning_options(), F__db_next_breakpoint_quiet__(), F__get__(), history_dock_widget::filter_activate(), workspace_view::filter_activate(), documentation_bookmarks::filter_activate(), KeyboardTranslator::findEntry(), Fpause(), Fwarning(), generate_completion(), get_mersenne_twister_state(), enter_shortcut::handle_direct_shortcut(), file_editor_tab::handle_margin_clicked(), main_window::handle_profiler_status_update(), enter_shortcut::handle_shift_modifier(), welcome_wizard::handle_web_connect_option(), init_mersenne_twister(), init_warning_options(), KeyboardTranslator::Entry::insertState(), KeyboardTranslator::Entry::matches(), next_state(), parseTransformationMatrix(), base_lexer::push_start_state(), textscan::scan(), textscan::scan_complex(), Figure::set_geometry(), set_mersenne_twister_state(), led_indicator::set_state(), error_system::set_warning_option(), set_warning_state(), KeyboardTranslator::Entry::setState(), textscan::skip_whitespace(), toggle_warn(), tree_evaluator::uwp_set_echo_state(), error_system::warning_enabled(), error_system::warning_query(), and xreset_default_properties().
|
static |
Definition at line 466 of file randmtzig.cc.
Referenced by create_ziggurat_tables(), rand_exponential< double >(), and documentation_browser::wheelEvent().
|
static |
Definition at line 464 of file randmtzig.cc.
Referenced by create_ziggurat_tables(), Faddeeva_w(), Fordschur(), FloatEIG::init(), EIG::init(), schur< T >::init(), rand_normal< double >(), and zbesy().