Ruby  2.5.0dev(2017-10-22revision60238)
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
random.c File Reference
#include "internal.h"
#include <limits.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <math.h>
#include <errno.h>
#include "ruby_atomic.h"
#include "siphash.c"

Go to the source code of this file.

Data Structures

struct  MT
 
struct  rb_random_t
 
struct  seed_keys_t
 

Macros

#define N   624
 
#define M   397
 
#define MATRIX_A   0x9908b0dfU /* constant vector a */
 
#define UMASK   0x80000000U /* most significant w-r bits */
 
#define LMASK   0x7fffffffU /* least significant r bits */
 
#define MIXBITS(u, v)   ( ((u) & UMASK) | ((v) & LMASK) )
 
#define TWIST(u, v)   ((MIXBITS((u),(v)) >> 1) ^ ((v)&1U ? MATRIX_A : 0U))
 
#define genrand_initialized(mt)   ((mt)->next != 0)
 
#define uninit_genrand(mt)   ((mt)->next = 0)
 
#define DEFAULT_SEED_CNT   4
 
#define SIZEOF_INT32   (31/CHAR_BIT + 1)
 
#define id_minus   '-'
 
#define id_plus   '+'
 
#define DEFAULT_SEED_LEN   (DEFAULT_SEED_CNT * (int)sizeof(int32_t))
 
#define USE_DEV_URANDOM   0
 
#define fill_random_bytes_urandom(seed, size)   -1
 
#define fill_random_bytes_syscall(seed, size, need_secure)   -1
 
#define SIP_HASH_STREAMING   0
 
#define sip_hash13   ruby_sip_hash13
 
#define BYTE_ORDER   LITTLE_ENDIAN
 
#define LITTLE_ENDIAN   1234
 
#define BIG_ENDIAN   4321
 

Typedefs

typedef int int_must_be_32bit_at_least[sizeof(int) *CHAR_BIT< 32 ? -1 :1]
 

Enumerations

enum  { MT_MAX_STATE = N }
 

Functions

unsigned int rb_genrand_int32 (void)
 
double rb_genrand_real (void)
 
unsigned long rb_genrand_ulong_limited (unsigned long limit)
 
unsigned int rb_random_int32 (VALUE obj)
 
double rb_random_real (VALUE obj)
 
unsigned long rb_random_ulong_limited (VALUE obj, unsigned long limit)
 
VALUE rb_random_bytes (VALUE obj, long n)
 
 NORETURN (static void domain_error(void))
 
 NORETURN (static void invalid_argument(VALUE))
 
st_index_t rb_hash_start (st_index_t h)
 
st_index_t rb_memhash (const void *ptr, long len)
 
void Init_RandomSeedCore (void)
 
void rb_reset_random_seed (void)
 
void InitVM_Random (void)
 
void Init_Random (void)
 

Variables

VALUE rb_cRandom
 

Macro Definition Documentation

◆ BIG_ENDIAN

#define BIG_ENDIAN   4321

Definition at line 1481 of file random.c.

◆ BYTE_ORDER

#define BYTE_ORDER   LITTLE_ENDIAN

Definition at line 1475 of file random.c.

Referenced by SHA256_Transform(), and SHA512_Transform().

◆ DEFAULT_SEED_CNT

#define DEFAULT_SEED_CNT   4

Definition at line 240 of file random.c.

Referenced by Init_RandomSeedCore().

◆ DEFAULT_SEED_LEN

#define DEFAULT_SEED_LEN   (DEFAULT_SEED_CNT * (int)sizeof(int32_t))

Definition at line 423 of file random.c.

◆ fill_random_bytes_syscall

#define fill_random_bytes_syscall (   seed,
  size,
  need_secure 
)    -1

Definition at line 535 of file random.c.

◆ fill_random_bytes_urandom

#define fill_random_bytes_urandom (   seed,
  size 
)    -1

Definition at line 461 of file random.c.

◆ genrand_initialized

#define genrand_initialized (   mt)    ((mt)->next != 0)

Definition at line 112 of file random.c.

◆ id_minus

#define id_minus   '-'

Definition at line 302 of file random.c.

◆ id_plus

#define id_plus   '+'

Definition at line 303 of file random.c.

◆ LITTLE_ENDIAN

#define LITTLE_ENDIAN   1234

Definition at line 1478 of file random.c.

Referenced by SHA256_Transform(), and SHA512_Transform().

◆ LMASK

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

Definition at line 99 of file random.c.

◆ M

#define M   397

Definition at line 96 of file random.c.

◆ MATRIX_A

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

Definition at line 97 of file random.c.

◆ MIXBITS

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

Definition at line 100 of file random.c.

◆ N

#define N   624

Definition at line 95 of file random.c.

◆ sip_hash13

#define sip_hash13   ruby_sip_hash13

Definition at line 1470 of file random.c.

Referenced by rb_memhash().

◆ SIP_HASH_STREAMING

#define SIP_HASH_STREAMING   0

Definition at line 1469 of file random.c.

◆ SIZEOF_INT32

#define SIZEOF_INT32   (31/CHAR_BIT + 1)

Definition at line 277 of file random.c.

◆ TWIST

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

Definition at line 101 of file random.c.

◆ UMASK

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

Definition at line 98 of file random.c.

◆ uninit_genrand

#define uninit_genrand (   mt)    ((mt)->next = 0)

Definition at line 113 of file random.c.

◆ USE_DEV_URANDOM

#define USE_DEV_URANDOM   0

Definition at line 428 of file random.c.

Typedef Documentation

◆ int_must_be_32bit_at_least

typedef int int_must_be_32bit_at_least[sizeof(int) *CHAR_BIT< 32 ? -1 :1]

Definition at line 92 of file random.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MT_MAX_STATE 

Definition at line 103 of file random.c.

Function Documentation

◆ Init_Random()

void Init_Random ( void  )

Definition at line 1643 of file random.c.

References InitVM, and rb_intern.

◆ Init_RandomSeedCore()

void Init_RandomSeedCore ( void  )

Definition at line 1525 of file random.c.

References DEFAULT_SEED_CNT.

◆ InitVM_Random()

void InitVM_Random ( void  )

Definition at line 1602 of file random.c.

References rb_define_global_function().

◆ NORETURN() [1/2]

NORETURN ( static void   domain_errorvoid)

◆ NORETURN() [2/2]

NORETURN ( static void   invalid_argumentVALUE)

◆ rb_genrand_int32()

unsigned int rb_genrand_int32 ( void  )

Definition at line 264 of file random.c.

◆ rb_genrand_real()

double rb_genrand_real ( void  )

Definition at line 271 of file random.c.

◆ rb_genrand_ulong_limited()

unsigned long rb_genrand_ulong_limited ( unsigned long  limit)

Definition at line 903 of file random.c.

◆ rb_hash_start()

st_index_t rb_hash_start ( st_index_t  h)

Definition at line 1506 of file random.c.

References st_hash_start().

Referenced by rb_dbl_long_hash().

◆ rb_memhash()

st_index_t rb_memhash ( const void *  ptr,
long  len 
)

Definition at line 1512 of file random.c.

References sip_hash13, and sip_uint64_t::u32.

Referenced by rb_dbl_long_hash(), and rb_str_hash().

◆ rb_random_bytes()

VALUE rb_random_bytes ( VALUE  obj,
long  n 
)

Definition at line 1117 of file random.c.

◆ rb_random_int32()

unsigned int rb_random_int32 ( VALUE  obj)

Definition at line 931 of file random.c.

◆ rb_random_real()

double rb_random_real ( VALUE  obj)

Definition at line 966 of file random.c.

◆ rb_random_ulong_limited()

unsigned long rb_random_ulong_limited ( VALUE  obj,
unsigned long  limit 
)

Definition at line 1026 of file random.c.

◆ rb_reset_random_seed()

void rb_reset_random_seed ( void  )

Definition at line 1570 of file random.c.

Variable Documentation

◆ key

Definition at line 1492 of file random.c.

◆ rb_cRandom

VALUE rb_cRandom

Definition at line 301 of file random.c.

◆ u32

Definition at line 1493 of file random.c.