Ruby
1.9.3p551(2014-11-13revision48407)
|
#include "ruby/ruby.h"
#include <limits.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <math.h>
#include <errno.h>
#include "siphash.c"
Go to the source code of this file.
Data Structures | |
struct | MT |
struct | rb_random_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 | BDIGITS(x) (RBIGNUM_DIGITS(x)) |
#define | BITSPERDIG (SIZEOF_BDIGITS*CHAR_BIT) |
#define | BIGRAD ((BDIGIT_DBL)1 << BITSPERDIG) |
#define | DIGSPERINT (SIZEOF_INT/SIZEOF_BDIGITS) |
#define | BIGUP(x) ((BDIGIT_DBL)(x) << BITSPERDIG) |
#define | BIGDN(x) RSHIFT((x),BITSPERDIG) |
#define | BIGLO(x) ((BDIGIT)((x) & (BIGRAD-1))) |
#define | BDIGMAX ((BDIGIT)-1) |
#define | roomof(n, m) (int)(((n)+(m)-1) / (m)) |
#define | numberof(array) (int)(sizeof(array) / sizeof((array)[0])) |
#define | SIZEOF_INT32 (31/CHAR_BIT + 1) |
#define | id_minus '-' |
#define | id_plus '+' |
#define | DEFAULT_SEED_LEN (DEFAULT_SEED_CNT * (int)sizeof(int)) |
#define | USE_DEV_URANDOM 0 |
#define | BIG_GET32(big, i) (RBIGNUM_DIGITS(big)[(i)]) |
#define | BIG_SET32(big, i, d) (RBIGNUM_DIGITS(big)[(i)] = (d)) |
#define | SIP_HASH_STREAMING 0 |
#define | sip_hash24 ruby_sip_hash24 |
#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 } |
Variables | |
static rb_random_t | default_rand |
VALUE | rb_cRandom |
static VALUE | rb_Random_DEFAULT |
static ID | id_rand |
static ID | id_bytes |
static const rb_data_type_t | random_data_type |
static st_index_t | hashseed |
union { | |
uint8_t key [16] | |
uint32_t u32 [(16 *sizeof(uint8_t)-1)/sizeof(uint32_t)] | |
} | sipseed |
#define BDIGITS | ( | x | ) | (RBIGNUM_DIGITS(x)) |
Definition at line 265 of file random.c.
Referenced by int_pair_to_real_inclusive(), and random_load().
#define BIG_GET32 | ( | big, | |
i | |||
) | (RBIGNUM_DIGITS(big)[(i)]) |
Referenced by limited_big_rand().
#define BIG_SET32 | ( | big, | |
i, | |||
d | |||
) | (RBIGNUM_DIGITS(big)[(i)] = (d)) |
Referenced by limited_big_rand().
#define BIGDN | ( | x | ) | RSHIFT((x),BITSPERDIG) |
Definition at line 270 of file random.c.
Referenced by mt_state().
Definition at line 271 of file random.c.
Referenced by mt_state().
#define BIGRAD ((BDIGIT_DBL)1 << BITSPERDIG) |
#define BIGUP | ( | x | ) | ((BDIGIT_DBL)(x) << BITSPERDIG) |
#define BITSPERDIG (SIZEOF_BDIGITS*CHAR_BIT) |
Definition at line 266 of file random.c.
Referenced by int_pair_to_real_inclusive(), rand_init(), and random_load().
#define BYTE_ORDER LITTLE_ENDIAN |
Definition at line 1271 of file random.c.
Referenced by SHA256_Transform(), and SHA512_Transform().
#define DEFAULT_SEED_CNT 4 |
Definition at line 228 of file random.c.
Referenced by Init_RandomSeed(), and random_seed().
#define DEFAULT_SEED_LEN (DEFAULT_SEED_CNT * (int)sizeof(int)) |
Definition at line 487 of file random.c.
Referenced by fill_random_seed(), init_randomseed(), and make_seed_value().
#define DIGSPERINT (SIZEOF_INT/SIZEOF_BDIGITS) |
Definition at line 268 of file random.c.
Referenced by random_load().
#define genrand_initialized | ( | mt | ) | ((mt)->next != 0) |
Definition at line 109 of file random.c.
Referenced by rand_start().
#define id_minus '-' |
Definition at line 331 of file random.c.
Referenced by range_values().
#define id_plus '+' |
Definition at line 332 of file random.c.
Referenced by rand_range().
#define LITTLE_ENDIAN 1234 |
Definition at line 1274 of file random.c.
Referenced by SHA256_Transform(), and SHA512_Transform().
#define M 397 |
Definition at line 93 of file random.c.
Referenced by next_state().
#define N 624 |
Definition at line 92 of file random.c.
Referenced by init_by_array(), init_genrand(), and next_state().
Definition at line 275 of file random.c.
Referenced by Init_RandomSeed(), mt_state(), rand_init(), random_copy(), and random_load().
Definition at line 274 of file random.c.
Referenced by int_pair_to_real_inclusive(), rand_init(), and random_load().
#define sip_hash24 ruby_sip_hash24 |
Definition at line 1266 of file random.c.
Referenced by rb_memhash().
#define SIZEOF_INT32 (31/CHAR_BIT + 1) |
Definition at line 276 of file random.c.
Referenced by limited_rand(), mt_state(), rand_init(), and rb_random_bytes().
Definition at line 98 of file random.c.
Referenced by next_state().
#define uninit_genrand | ( | mt | ) | ((mt)->next = 0) |
Definition at line 110 of file random.c.
Referenced by rb_reset_random_seed().
Definition at line 246 of file random.c.
References rb_random_t::mt, and rand_start().
Referenced by rb_f_rand(), rb_genrand_int32(), rb_genrand_real(), and rb_genrand_ulong_limited().
Definition at line 496 of file random.c.
References CHAR_BIT, DEFAULT_SEED_LEN, fstat, gettimeofday(), int, memset(), n, NULL, O_NONBLOCK, rb_update_max_fd(), S_ISCHR, stat, timeval::tv_sec, and timeval::tv_usec.
Referenced by init_randomseed(), and random_seed().
|
inlinestatic |
Definition at line 1023 of file random.c.
References INT2FIX, isinf(), isnan, rb_class_new_instance(), rb_eSystemCallError, rb_exc_raise(), and RFLOAT_VALUE.
Referenced by rand_range(), and random_rand().
Definition at line 180 of file random.c.
References MT::left, MT::next, and next_state().
Referenced by genrand_real(), genrand_real2(), Init_RandomSeed(), limited_big_rand(), limited_rand(), rb_genrand_int32(), rb_random_bytes(), and rb_random_int32().
|
static |
Definition at line 199 of file random.c.
References a, b, and genrand_int32().
Referenced by rand_range(), random_rand(), rb_f_rand(), rb_genrand_real(), and rb_random_real().
|
static |
Definition at line 209 of file random.c.
References a, b, genrand_int32(), and int_pair_to_real_inclusive().
Referenced by rand_range().
|
static |
Definition at line 365 of file random.c.
References ptr, and TypedData_Get_Struct.
Referenced by random_copy(), random_dump(), random_equal(), random_get_seed(), random_init(), random_left(), random_load(), random_rand(), and random_state().
Definition at line 135 of file random.c.
References i, init_genrand(), N, and MT::state.
Referenced by init_randomseed(), and rand_init().
Definition at line 114 of file random.c.
References MT::left, N, MT::next, and MT::state.
Referenced by init_by_array(), and rand_init().
Definition at line 1365 of file random.c.
References CLASS_OF, id_bytes, id_rand, Init_RandomSeed2(), random_alloc(), random_bytes(), random_copy(), random_dump(), random_equal(), random_get_seed(), random_init(), random_left(), random_load(), random_rand(), random_s_left(), random_s_rand(), random_s_state(), random_seed(), random_state(), rb_cObject, rb_cRandom, rb_define_alloc_func(), rb_define_class(), rb_define_const(), rb_define_global_function(), rb_define_method(), rb_define_private_method(), rb_define_singleton_method(), rb_f_rand(), rb_f_srand(), rb_global_variable(), rb_intern, rb_Random_DEFAULT, and TypedData_Wrap_Struct.
Definition at line 1289 of file random.c.
References DEFAULT_SEED_LEN, fill_random_seed(), init_by_array(), make_seed_value(), and memset().
Referenced by Init_RandomSeed().
Definition at line 1300 of file random.c.
References default_rand, DEFAULT_SEED_CNT, genrand_int32(), hashseed, i, init_randomseed(), rb_random_t::mt, numberof, r, rb_global_variable(), rb_random_t::seed, and sipseed.
Definition at line 1347 of file random.c.
References rb_cBignum, RB_TYPE_P, RBASIC, rb_random_t::seed, and T_BIGNUM.
Referenced by Init_Random().
Definition at line 279 of file random.c.
References BDIGIT, BDIGITS, BITSPERDIG, FIX2ULONG, FIXNUM_P, i, INT2FIX, len, m, MEMMOVE, MEMZERO, r, rb_big2dbl(), rb_big_mul(), rb_big_new(), rb_big_rshift(), RBIGNUM_LEN, and roomof.
Referenced by genrand_real2().
Definition at line 833 of file random.c.
References BDIGIT, BIG_GET32, BIG_SET32, genrand_int32(), i, len, make_mask(), rb_big_clone(), rb_big_norm(), RBIGNUM_LEN, RBIGNUM_SET_SIGN, SIZEOF_BDIGITS, and val.
Referenced by rand_int(), and rand_range().
Definition at line 811 of file random.c.
References genrand_int32(), i, long, make_mask(), SIZEOF_INT32, and val.
Referenced by rand_int(), rand_range(), and rb_genrand_ulong_limited().
Definition at line 797 of file random.c.
Referenced by limited_big_rand(), and limited_rand().
Definition at line 547 of file random.c.
References BDIGIT, DEFAULT_SEED_LEN, len, MEMCPY, NEWOBJ, OBJSETUP, rb_big_norm(), rb_big_resize(), rb_cBignum, RBIGNUM_DIGITS, RBIGNUM_SET_SIGN, SIZEOF_BDIGITS, and T_BIGNUM.
Referenced by init_randomseed(), and random_seed().
Definition at line 610 of file random.c.
References BDIGIT, BIGDN, BIGLO, d, i, numberof, rb_big_new(), rb_big_norm(), RBIGNUM_DIGITS, SIZEOF_BDIGITS, SIZEOF_INT32, and MT::state.
Referenced by random_dump(), random_s_state(), and random_state().
Definition at line 393 of file random.c.
References ALLOC_N, BITSPERDIG, buf, FIX2LONG, i, init_by_array(), init_genrand(), int, len, memset(), MT_MAX_STATE, numberof, rb_eTypeError, rb_obj_classname(), rb_raise(), rb_to_int(), RBIGNUM_DIGITS, RBIGNUM_LEN, roomof, SIZEOF_BDIGITS, SIZEOF_INT32, T_BIGNUM, T_FIXNUM, TYPE, and xfree.
Referenced by rand_start(), random_init(), and rb_f_srand().
Definition at line 985 of file random.c.
References FIX2LONG, FIXNUM_P, INT2FIX, limited_big_rand(), limited_rand(), LONG2NUM, Qnil, r, rb_big_clone(), rb_big_minus(), rb_bigzero_p(), RB_GC_GUARD, RBIGNUM, RBIGNUM_SET_SIGN, RBIGNUM_SIGN, ret, and ULONG2NUM().
Referenced by random_rand(), and rb_f_rand().
Definition at line 1034 of file random.c.
References BUILTIN_TYPE, end, FIX2LONG, FIXNUM_P, float_value(), genrand_real(), genrand_real2(), id_plus, INT2FIX, isinf(), limited_big_rand(), limited_rand(), LONG2NUM, NIL_P, Qfalse, Qnil, Qundef, r, range_values(), rb_big_minus(), rb_big_norm(), rb_big_plus(), rb_bigzero_p(), rb_check_to_float(), rb_check_to_integer(), rb_float_new(), rb_funcall2(), rb_to_float(), RBIGNUM, RBIGNUM_SIGN, RFLOAT_VALUE, T_BIGNUM, T_FLOAT, T_NIL, TYPE, ULONG2NUM(), and v.
Referenced by random_rand(), and rb_f_rand().
|
static |
Definition at line 236 of file random.c.
References genrand_initialized, rb_random_t::mt, r, rand_init(), random_seed(), and rb_random_t::seed.
Referenced by default_mt(), random_s_rand(), and try_get_rnd().
Definition at line 384 of file random.c.
References INT2FIX, obj, rb_random_t::seed, and TypedData_Make_Struct.
Referenced by Init_Random().
Definition at line 934 of file random.c.
References NUM2LONG(), rb_random_bytes(), and rb_to_int().
Referenced by Init_Random().
Definition at line 598 of file random.c.
References get_rnd(), MT::left, rb_random_t::mt, MT::next, numberof, obj, and MT::state.
Referenced by Init_Random().
Definition at line 663 of file random.c.
References get_rnd(), INT2FIX, MT::left, rb_random_t::mt, mt_state(), rb_ary_new2(), rb_ary_push(), and rb_random_t::seed.
Referenced by Init_Random().
Definition at line 1188 of file random.c.
References get_rnd(), MT::left, memcmp(), rb_random_t::mt, MT::next, Qfalse, Qtrue, rb_funcall2(), rb_intern, rb_obj_class(), RTEST, rb_random_t::seed, and MT::state.
Referenced by Init_Random().
Definition at line 591 of file random.c.
References get_rnd(), and rb_random_t::seed.
Referenced by Init_Random().
Definition at line 472 of file random.c.
References get_rnd(), rb_random_t::mt, obj, rand_init(), random_seed(), rb_scan_args(), and rb_random_t::seed.
Referenced by Init_Random().
Definition at line 648 of file random.c.
References get_rnd(), INT2FIX, MT::left, and rb_random_t::mt.
Referenced by Init_Random().
Definition at line 677 of file random.c.
References ary, BDIGIT, BDIGITS, BITSPERDIG, Check_Type, d, DIGSPERINT, FIX2ULONG, FIXNUM_P, get_rnd(), int, INT2FIX, MT::left, len, memset(), rb_random_t::mt, MT::next, NUM2ULONG, numberof, obj, RARRAY_LEN, RARRAY_PTR(), rb_eArgError, rb_raise(), rb_to_int(), RBIGNUM_DIGITS, RBIGNUM_LEN, roomof, rb_random_t::seed, SIZEOF_BDIGITS, MT::state, T_ARRAY, and T_BIGNUM.
Referenced by Init_Random().
Definition at line 337 of file random.c.
References rb_gc_mark().
Definition at line 1140 of file random.c.
References float_value(), genrand_real(), get_rnd(), rb_random_t::mt, NIL_P, NUM2LONG(), Qfalse, Qnil, rand_int(), rand_range(), rb_check_to_float(), rb_check_to_integer(), rb_eArgError, rb_exc_new3(), rb_exc_raise(), rb_float_new(), rb_obj_as_string(), rb_raise(), rb_str_append(), rb_str_new_cstr(), T_FLOAT, TYPE, v, and void.
Referenced by Init_Random(), and random_s_rand().
Definition at line 656 of file random.c.
References INT2FIX, MT::left, and rb_random_t::mt.
Referenced by Init_Random().
Definition at line 1259 of file random.c.
References rand_start(), random_rand(), and rb_Random_DEFAULT.
Referenced by Init_Random().
Definition at line 641 of file random.c.
References rb_random_t::mt, and mt_state().
Referenced by Init_Random().
Definition at line 578 of file random.c.
References buf, DEFAULT_SEED_CNT, fill_random_seed(), and make_seed_value().
Referenced by Init_Random(), rand_start(), random_init(), and rb_f_srand().
Definition at line 633 of file random.c.
References get_rnd(), rb_random_t::mt, and mt_state().
Referenced by Init_Random().
Definition at line 972 of file random.c.
References end, id_minus, NIL_P, Qfalse, r, rb_funcall2(), rb_range_values(), and rb_respond_to().
Referenced by rand_range().
Definition at line 1230 of file random.c.
References DBL2NUM, default_mt(), genrand_real(), INT2FIX, NIL_P, Qfalse, r, rand_int(), rand_range(), rb_scan_args(), rb_to_int(), and v.
Referenced by Init_Random().
Definition at line 778 of file random.c.
References default_rand, rb_random_t::mt, r, rand_init(), random_seed(), rb_scan_args(), rb_secure(), and rb_random_t::seed.
Referenced by Init_Random().
Definition at line 252 of file random.c.
References default_mt(), and genrand_int32().
double rb_genrand_real | ( | void | ) |
Definition at line 259 of file random.c.
References default_mt(), and genrand_real().
Definition at line 890 of file random.c.
References default_mt(), and limited_rand().
Referenced by big_sparse_p().
st_index_t rb_hash_start | ( | st_index_t | h | ) |
Definition at line 1330 of file random.c.
References hashseed, and st_hash_start.
Referenced by match_hash(), method_hash(), proc_hash(), rb_any_hash(), rb_obj_hash(), and recursive_hash().
st_index_t rb_memhash | ( | const void * | ptr, |
long | len | ||
) |
Definition at line 1336 of file random.c.
References sip_hash24, sipseed, and sip_uint64_t::u32.
Referenced by BigDecimal_hash(), d_lite_hash(), flo_hash(), match_hash(), nucomp_hash(), nurat_hash(), rb_big_hash(), rb_str_hash(), and reg_hash().
Definition at line 940 of file random.c.
References CHAR_BIT, genrand_int32(), i, id_bytes, len, LONG2NUM, rb_random_t::mt, ptr, r, rb_funcall2(), rb_str_new(), RSTRING_PTR, SIZEOF_INT32, and try_get_rnd().
Referenced by random_bytes().
Definition at line 896 of file random.c.
References genrand_int32(), id_rand, INT2FIX, rb_random_t::mt, NUM2ULONG, rb_big_plus(), rb_funcall2(), try_get_rnd(), and ULONG2NUM().
double rb_random_real | ( | VALUE | obj | ) |
Definition at line 913 of file random.c.
References d, genrand_real(), id_rand, rb_random_t::mt, NUM2DBL, rb_eRangeError, rb_funcall2(), rb_raise(), try_get_rnd(), and v.
Referenced by rb_ary_sample().
Definition at line 1357 of file random.c.
References default_rand, INT2FIX, rb_random_t::mt, r, rb_random_t::seed, and uninit_genrand.
Referenced by rb_thread_atfork().
|
static |
Definition at line 373 of file random.c.
References DATA_PTR(), NULL, rand_start(), rb_cRandom, and rb_typeddata_is_kind_of().
Referenced by rb_random_bytes(), rb_random_int32(), and rb_random_real().
|
static |
Definition at line 230 of file random.c.
Referenced by Init_RandomSeed(), rb_f_srand(), and rb_reset_random_seed().
|
static |
Definition at line 1282 of file random.c.
Referenced by Init_RandomSeed(), and rb_hash_start().
|
static |
Definition at line 333 of file random.c.
Referenced by Init_Random(), and rb_random_bytes().
|
static |
Definition at line 333 of file random.c.
Referenced by Init_Random(), rb_random_int32(), and rb_random_real().
|
static |
|
static |
Definition at line 330 of file random.c.
Referenced by Init_Random(), and random_s_rand().
union { ... } sipseed |
Referenced by Init_RandomSeed(), and rb_memhash().