1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

random.c: seed conversion

* random.c (rand_init): random_seed() always returns an Integer,
  no conversion for it.

* random.c (random_init, rb_f_srand): convert the given seed to an
  Integer.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-05-09 03:52:09 +00:00
parent 639bfd6d9c
commit ad949e8f31

View file

@ -368,8 +368,6 @@ rand_init(struct MT *mt, VALUE seed)
size_t len;
int sign;
seed = rb_to_int(seed);
len = rb_absint_numwords(seed, 32, NULL);
if (len > numberof(buf0))
buf = ALLOC_N(uint32_t, len);
@ -415,6 +413,7 @@ random_init(int argc, VALUE *argv, VALUE obj)
else {
vseed = argv[0];
rb_check_copyable(obj, vseed);
vseed = rb_to_int(vseed);
}
rnd->seed = rand_init(&rnd->mt, vseed);
return obj;
@ -784,7 +783,7 @@ rb_f_srand(int argc, VALUE *argv, VALUE obj)
seed = random_seed();
}
else {
seed = argv[0];
seed = rb_to_int(argv[0]);
}
old = r->seed;
r->seed = rand_init(&r->mt, seed);