Last active
March 29, 2016 16:53
-
-
Save cassiomarques/5a4a5472b99117f799e5924268960124 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1] pry(main)> show-source Random.rand | |
From: random.c (C Method): | |
Owner: #<Class:Random> | |
Visibility: public | |
Number of lines: 5 | |
static VALUE | |
random_s_rand(int argc, VALUE *argv, VALUE obj) | |
{ | |
return rand_random(argc, argv, rand_start(&default_rand)); | |
} | |
[2] pry(main)> show-source Random.srand | |
From: random.c (C Method): | |
Owner: #<Class:Random> | |
Visibility: public | |
Number of lines: 18 | |
static VALUE | |
rb_f_srand(int argc, VALUE *argv, VALUE obj) | |
{ | |
VALUE seed, old; | |
rb_random_t *r = &default_rand; | |
rb_secure(4); | |
if (argc == 0) { | |
seed = random_seed(); | |
} | |
else { | |
rb_scan_args(argc, argv, "01", &seed); | |
} | |
old = r->seed; | |
r->seed = rand_init(&r->mt, seed); | |
return old; | |
} | |
[5] pry(main)> show-source rand | |
From: random.c (C Method): | |
Owner: Kernel | |
Visibility: private | |
Number of lines: 19 | |
static VALUE | |
rb_f_rand(int argc, VALUE *argv, VALUE obj) | |
{ | |
VALUE v, vmax, r; | |
struct MT *mt = default_mt(); | |
if (argc == 0) goto zero_arg; | |
rb_scan_args(argc, argv, "01", &vmax); | |
if (NIL_P(vmax)) goto zero_arg; | |
if ((v = rand_range(mt, vmax)) != Qfalse) { | |
return v; | |
} | |
vmax = rb_to_int(vmax); | |
if (vmax == INT2FIX(0) || NIL_P(r = rand_int(mt, vmax, 0))) { | |
zero_arg: | |
return DBL2NUM(genrand_real(mt)); | |
} | |
return r; | |
} | |
[6] pry(main)> show-source srand | |
From: random.c (C Method): | |
Owner: Kernel | |
Visibility: private | |
Number of lines: 18 | |
static VALUE | |
rb_f_srand(int argc, VALUE *argv, VALUE obj) | |
{ | |
VALUE seed, old; | |
rb_random_t *r = &default_rand; | |
rb_secure(4); | |
if (argc == 0) { | |
seed = random_seed(); | |
} | |
else { | |
rb_scan_args(argc, argv, "01", &seed); | |
} | |
old = r->seed; | |
r->seed = rand_init(&r->mt, seed); | |
return old; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment