GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
rand Class Reference

#include "oct-rand.h"

Collaboration diagram for rand:

Public Member Functions

 ~rand (void)=default
 
template<typename T >
do_scalar (T a)
 
template<typename T >
Array< T > do_vector (octave_idx_type n, T a)
 

Static Public Member Functions

static void distribution (const std::string &d)
 
static std::string distribution (void)
 
static void exponential_distribution (void)
 
static FloatNDArray float_nd_array (const dim_vector &dims, float a=1.0)
 
static float float_scalar (float a=1.0)
 
static Array< float > float_vector (octave_idx_type n, float a=1.0)
 
static void gamma_distribution (void)
 
static bool instance_ok (void)
 
static NDArray nd_array (const dim_vector &dims, double a=1.0)
 
static void normal_distribution (void)
 
static void poisson_distribution (void)
 
static void reset (const std::string &d)
 
static void reset (void)
 
static double scalar (double a=1.0)
 
static void seed (double s)
 
static double seed (void)
 
static uint32NDArray state (const std::string &d="")
 
static void state (const uint32NDArray &s, const std::string &d="")
 
static void uniform_distribution (void)
 
static Array< double > vector (octave_idx_type n, double a=1.0)
 

Protected Member Functions

OCTAVE_API rand (void)
 

Private Types

enum  {
  unknown_dist , uniform_dist , normal_dist , expon_dist ,
  poisson_dist , gamma_dist
}
 

Private Member Functions

OCTAVE_API void do_distribution (const std::string &d)
 
OCTAVE_API std::string do_distribution (void)
 
OCTAVE_API void do_exponential_distribution (void)
 
OCTAVE_API FloatNDArray do_float_nd_array (const dim_vector &dims, float a=1.)
 
OCTAVE_API void do_gamma_distribution (void)
 
OCTAVE_API NDArray do_nd_array (const dim_vector &dims, double a=1.)
 
OCTAVE_API void do_normal_distribution (void)
 
OCTAVE_API void do_poisson_distribution (void)
 
OCTAVE_API void do_reset ()
 
OCTAVE_API void do_reset (const std::string &d)
 
template<typename T >
OCTAVE_APIdo_scalar (T a=1)
 
OCTAVE_API void do_seed (double s)
 
OCTAVE_API double do_seed (void)
 
OCTAVE_API uint32NDArray do_state (const std::string &d)
 
OCTAVE_API void do_state (const uint32NDArray &s, const std::string &d)
 
OCTAVE_API void do_uniform_distribution (void)
 
template<typename T >
OCTAVE_API Array< T > do_vector (octave_idx_type n, T a=1)
 
template<>
OCTAVE_API double exponential (void)
 
template<>
OCTAVE_API float exponential (void)
 
template<typename T >
OCTAVE_APIexponential (void)
 
OCTAVE_API void fill (octave_idx_type len, double *v, double a)
 
OCTAVE_API void fill (octave_idx_type len, float *v, float a)
 
template<>
OCTAVE_API double gamma (double a)
 
template<>
OCTAVE_API float gamma (float a)
 
template<typename T >
OCTAVE_APIgamma (T a)
 
OCTAVE_API int get_dist_id (const std::string &d)
 
OCTAVE_API uint32NDArray get_internal_state (void)
 
OCTAVE_API void initialize_mersenne_twister (void)
 
OCTAVE_API void initialize_ranlib_generators (void)
 
template<>
OCTAVE_API double normal (void)
 
template<>
OCTAVE_API float normal (void)
 
template<typename T >
OCTAVE_APInormal (void)
 
template<>
OCTAVE_API double poisson (double a)
 
template<>
OCTAVE_API float poisson (float a)
 
template<typename T >
OCTAVE_APIpoisson (T a)
 
OCTAVE_API void save_state (void)
 
OCTAVE_API void set_internal_state (const uint32NDArray &s)
 
OCTAVE_API void switch_to_generator (int dist)
 
template<>
OCTAVE_API double uniform (void)
 
template<>
OCTAVE_API float uniform (void)
 
template<typename T >
OCTAVE_APIuniform (void)
 

Static Private Member Functions

static void cleanup_instance (void)
 

Private Attributes

int m_current_distribution
 
std::map< int, uint32NDArraym_rand_states
 
bool m_use_old_generators
 

Static Private Attributes

static randm_instance = nullptr
 

Detailed Description

Definition at line 44 of file oct-rand.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
unknown_dist 
uniform_dist 
normal_dist 
expon_dist 
poisson_dist 
gamma_dist 

Definition at line 190 of file oct-rand.h.

Constructor & Destructor Documentation

◆ rand()

rand::rand ( void  )
protected

Definition at line 53 of file oct-rand.cc.

References initialize_mersenne_twister(), and initialize_ranlib_generators().

Referenced by instance_ok().

◆ ~rand()

rand::~rand ( void  )
default

Member Function Documentation

◆ cleanup_instance()

static void rand::cleanup_instance ( void  )
inlinestaticprivate

Definition at line 187 of file oct-rand.h.

Referenced by instance_ok().

◆ distribution() [1/2]

static void rand::distribution ( const std::string &  d)
inlinestatic

Definition at line 106 of file oct-rand.h.

References d.

◆ distribution() [2/2]

static std::string rand::distribution ( void  )
inlinestatic

Definition at line 99 of file oct-rand.h.

Referenced by do_rand().

◆ do_distribution() [1/2]

void rand::do_distribution ( const std::string &  d)
private

◆ do_distribution() [2/2]

std::string rand::do_distribution ( void  )
private

◆ do_exponential_distribution()

void rand::do_exponential_distribution ( void  )
private

Definition at line 272 of file oct-rand.cc.

References expon_dist, F77_FUNC(), and switch_to_generator().

◆ do_float_nd_array()

FloatNDArray rand::do_float_nd_array ( const dim_vector dims,
float  a = 1. 
)
private

◆ do_gamma_distribution()

void rand::do_gamma_distribution ( void  )
private

Definition at line 286 of file oct-rand.cc.

References F77_FUNC(), gamma_dist, and switch_to_generator().

◆ do_nd_array()

NDArray rand::do_nd_array ( const dim_vector dims,
double  a = 1. 
)
private

◆ do_normal_distribution()

void rand::do_normal_distribution ( void  )
private

Definition at line 265 of file oct-rand.cc.

References F77_FUNC(), normal_dist, and switch_to_generator().

◆ do_poisson_distribution()

void rand::do_poisson_distribution ( void  )
private

Definition at line 279 of file oct-rand.cc.

References F77_FUNC(), poisson_dist, and switch_to_generator().

◆ do_reset() [1/2]

void rand::do_reset ( void  )
private

Definition at line 138 of file oct-rand.cc.

References initialize_ranlib_generators(), and m_use_old_generators.

◆ do_reset() [2/2]

void rand::do_reset ( const std::string &  d)
private

◆ do_scalar() [1/2]

template<typename T >
T rand::do_scalar ( a)

◆ do_scalar() [2/2]

template<typename T >
OCTAVE_API T rand::do_scalar ( a = 1)
private

◆ do_seed() [1/2]

void rand::do_seed ( double  s)
private

◆ do_seed() [2/2]

double rand::do_seed ( void  )
private

Definition at line 75 of file oct-rand.cc.

References d, F77_FUNC(), flt_fmt_ieee_big_endian, getsd(), and native_float_format().

◆ do_state() [1/2]

uint32NDArray rand::do_state ( const std::string &  d)
private

Definition at line 144 of file oct-rand.cc.

References d, get_dist_id(), m_current_distribution, and m_rand_states.

◆ do_state() [2/2]

void rand::do_state ( const uint32NDArray s,
const std::string &  d 
)
private

◆ do_uniform_distribution()

void rand::do_uniform_distribution ( void  )
private

Definition at line 258 of file oct-rand.cc.

References F77_FUNC(), switch_to_generator(), and uniform_dist.

◆ do_vector() [1/2]

template<typename T >
Array<T> rand::do_vector ( octave_idx_type  n,
a 
)

◆ do_vector() [2/2]

template<typename T >
OCTAVE_API Array<T> rand::do_vector ( octave_idx_type  n,
a = 1 
)
private

◆ exponential() [1/3]

template<>
OCTAVE_API double rand::exponential ( void  )
private

Definition at line 320 of file oct-rand.cc.

References dgenexp(), F77_FUNC(), m_use_old_generators, and rand_exponential< double >().

◆ exponential() [2/3]

template<>
OCTAVE_API float rand::exponential ( void  )
private

Definition at line 399 of file oct-rand.cc.

References F77_FUNC(), fgenexp(), m_use_old_generators, and rand_exponential< float >().

◆ exponential() [3/3]

template<typename T >
OCTAVE_API T rand::exponential ( void  )
private

◆ exponential_distribution()

static void rand::exponential_distribution ( void  )
inlinestatic

Definition at line 124 of file oct-rand.h.

Referenced by do_distribution(), and do_rand().

◆ fill() [1/2]

◆ fill() [2/2]

◆ float_nd_array()

static FloatNDArray rand::float_nd_array ( const dim_vector dims,
float  a = 1.0 
)
inlinestatic

Definition at line 177 of file oct-rand.h.

Referenced by do_rand().

◆ float_scalar()

static float rand::float_scalar ( float  a = 1.0)
inlinestatic

Definition at line 150 of file oct-rand.h.

References NaN.

Referenced by do_rand().

◆ float_vector()

static Array<float> rand::float_vector ( octave_idx_type  n,
float  a = 1.0 
)
inlinestatic

Definition at line 163 of file oct-rand.h.

References Array< float >, and n.

◆ gamma() [1/3]

template<>
OCTAVE_API double rand::gamma ( double  a)
private

Definition at line 355 of file oct-rand.cc.

References dgengam(), F77_FUNC(), isfinite(), m_use_old_generators, and NaN.

◆ gamma() [2/3]

template<>
OCTAVE_API float rand::gamma ( float  a)
private

Definition at line 437 of file oct-rand.cc.

References F77_FUNC(), fgengam(), isfinite(), m_use_old_generators, and NaN.

◆ gamma() [3/3]

template<typename T >
OCTAVE_API T rand::gamma ( a)
private

◆ gamma_distribution()

static void rand::gamma_distribution ( void  )
inlinestatic

Definition at line 136 of file oct-rand.h.

Referenced by do_distribution(), and do_rand().

◆ get_dist_id()

int rand::get_dist_id ( const std::string &  d)
private

◆ get_internal_state()

uint32NDArray rand::get_internal_state ( void  )
private

◆ initialize_mersenne_twister()

void rand::initialize_mersenne_twister ( void  )
private

◆ initialize_ranlib_generators()

void rand::initialize_ranlib_generators ( void  )
private

Definition at line 552 of file oct-rand.cc.

References F77_FUNC(), force_to_fit_range(), m_current_distribution, setall(), and uniform_dist.

Referenced by rand(), and do_reset().

◆ instance_ok()

bool rand::instance_ok ( void  )
static

Definition at line 62 of file oct-rand.cc.

References rand(), singleton_cleanup_list::add(), cleanup_instance(), and m_instance.

◆ nd_array()

static NDArray rand::nd_array ( const dim_vector dims,
double  a = 1.0 
)
inlinestatic

Definition at line 170 of file oct-rand.h.

References NDArray.

Referenced by do_rand(), and Frandperm().

◆ normal() [1/3]

template<>
OCTAVE_API double rand::normal ( void  )
private

Definition at line 307 of file oct-rand.cc.

References dgennor(), F77_FUNC(), m_use_old_generators, and rand_normal< double >().

◆ normal() [2/3]

template<>
OCTAVE_API float rand::normal ( void  )
private

Definition at line 386 of file oct-rand.cc.

References F77_FUNC(), fgennor(), m_use_old_generators, and rand_normal< float >().

◆ normal() [3/3]

template<typename T >
OCTAVE_API T rand::normal ( void  )
private

◆ normal_distribution()

static void rand::normal_distribution ( void  )
inlinestatic

Definition at line 118 of file oct-rand.h.

Referenced by do_distribution(), and do_rand().

◆ poisson() [1/3]

template<>
OCTAVE_API double rand::poisson ( double  a)
private

◆ poisson() [2/3]

template<>
OCTAVE_API float rand::poisson ( float  a)
private

◆ poisson() [3/3]

template<typename T >
OCTAVE_API T rand::poisson ( a)
private

◆ poisson_distribution()

static void rand::poisson_distribution ( void  )
inlinestatic

Definition at line 130 of file oct-rand.h.

Referenced by do_distribution(), and do_rand().

◆ reset() [1/2]

static void rand::reset ( const std::string &  d)
inlinestatic

Definition at line 92 of file oct-rand.h.

References d.

◆ reset() [2/2]

static void rand::reset ( void  )
inlinestatic

Definition at line 71 of file oct-rand.h.

Referenced by do_rand().

◆ save_state()

void rand::save_state ( void  )
private

Definition at line 610 of file oct-rand.cc.

References get_internal_state(), m_current_distribution, and m_rand_states.

Referenced by do_scalar(), and fill().

◆ scalar()

static double rand::scalar ( double  a = 1.0)
inlinestatic

Definition at line 143 of file oct-rand.h.

References NaN.

Referenced by do_rand().

◆ seed() [1/2]

static void rand::seed ( double  s)
inlinestatic

Definition at line 64 of file oct-rand.h.

◆ seed() [2/2]

static double rand::seed ( void  )
inlinestatic

Definition at line 57 of file oct-rand.h.

References NaN.

Referenced by do_rand().

◆ set_internal_state()

void rand::set_internal_state ( const uint32NDArray s)
private

◆ state() [1/2]

static uint32NDArray rand::state ( const std::string &  d = "")
inlinestatic

Definition at line 78 of file oct-rand.h.

References d.

Referenced by do_rand().

◆ state() [2/2]

static void rand::state ( const uint32NDArray s,
const std::string &  d = "" 
)
inlinestatic

Definition at line 84 of file oct-rand.h.

References d.

◆ switch_to_generator()

void rand::switch_to_generator ( int  dist)
private

◆ uniform() [1/3]

template<>
OCTAVE_API double rand::uniform ( void  )
private

Definition at line 294 of file oct-rand.cc.

References dgenunf(), F77_FUNC(), m_use_old_generators, and rand_uniform< double >().

◆ uniform() [2/3]

template<>
OCTAVE_API float rand::uniform ( void  )
private

Definition at line 373 of file oct-rand.cc.

References F77_FUNC(), fgenunf(), m_use_old_generators, and rand_uniform< float >().

◆ uniform() [3/3]

template<typename T >
OCTAVE_API T rand::uniform ( void  )
private

◆ uniform_distribution()

static void rand::uniform_distribution ( void  )
inlinestatic

Definition at line 112 of file oct-rand.h.

Referenced by do_distribution(), and do_rand().

◆ vector()

static Array<double> rand::vector ( octave_idx_type  n,
double  a = 1.0 
)
inlinestatic

Definition at line 157 of file oct-rand.h.

References Array< double >, and n.

Member Data Documentation

◆ m_current_distribution

int rand::m_current_distribution
private

◆ m_instance

rand * rand::m_instance = nullptr
staticprivate

Definition at line 185 of file oct-rand.h.

Referenced by instance_ok().

◆ m_rand_states

std::map<int, uint32NDArray> rand::m_rand_states
private

◆ m_use_old_generators

bool rand::m_use_old_generators
private

The documentation for this class was generated from the following files: