diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-03-15 03:26:29 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-03-15 03:26:29 +0000 |
commit | 1bf3ca494f89e56ca267b30ce85ff100994e7b64 (patch) | |
tree | ed044251e1744c6b1ded906759082321cb30d6a0 /random.c | |
parent | e03b66ef183ec828dc9422d514af750915767e77 (diff) | |
download | ruby-1bf3ca494f89e56ca267b30ce85ff100994e7b64.tar.gz |
* random.c (rb_reset_random_seed): set seed in this. [ruby-core:28655]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26936 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'random.c')
-rw-r--r-- | random.c | 28 |
1 files changed, 22 insertions, 6 deletions
@@ -223,16 +223,34 @@ struct Random { static struct Random default_rand; +static VALUE rand_init(struct MT *mt, VALUE vseed); +static VALUE random_seed(void); + +static void +default_rand_init(void) +{ + rb_random_t *r = &default_rand.rnd; + r->seed = rand_init(&r->mt, random_seed()); +} + unsigned int rb_genrand_int32(void) { - return genrand_int32(&default_rand.rnd.mt); + struct MT *mt = &default_rand.rnd.mt; + if (!genrand_initialized(mt)) { + default_rand_init(); + } + return genrand_int32(mt); } double rb_genrand_real(void) { - return genrand_real(&default_rand.rnd.mt); + struct MT *mt = &default_rand.rnd.mt; + if (!genrand_initialized(mt)) { + default_rand_init(); + } + return genrand_real(mt); } #define BDIGITS(x) (RBIGNUM_DIGITS(x)) @@ -303,8 +321,6 @@ VALUE rb_cRandom; #define id_minus '-' #define id_plus '+' -static VALUE random_seed(void); - /* :nodoc: */ static void random_mark(void *ptr) @@ -831,7 +847,7 @@ rb_rand_internal(unsigned long i) { struct MT *mt = &default_rand.rnd.mt; if (!genrand_initialized(mt)) { - rand_init(mt, random_seed()); + default_rand_init(); } return limited_rand(mt, i); } @@ -1111,7 +1127,7 @@ rb_f_rand(int argc, VALUE *argv, VALUE obj) struct MT *mt = &default_rand.rnd.mt; if (!genrand_initialized(mt)) { - rand_init(mt, random_seed()); + default_rand_init(); } if (argc == 0) goto zero_arg; rb_scan_args(argc, argv, "01", &vmax); |