mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
* array.c (rb_ary_{shuffle_bang,sample}): use Random class object.
* random.c (try_get_rnd): use default_rand for Random as same as singleton methods. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
569d821929
commit
ae6a9009dc
3 changed files with 20 additions and 7 deletions
16
random.c
16
random.c
|
@ -229,15 +229,20 @@ static rb_random_t default_rand;
|
|||
static VALUE rand_init(struct MT *mt, VALUE vseed);
|
||||
static VALUE random_seed(void);
|
||||
|
||||
static struct MT *
|
||||
default_mt(void)
|
||||
static rb_random_t *
|
||||
rand_start(rb_random_t *r)
|
||||
{
|
||||
rb_random_t *r = &default_rand;
|
||||
struct MT *mt = &r->mt;
|
||||
if (!genrand_initialized(mt)) {
|
||||
r->seed = rand_init(mt, random_seed());
|
||||
}
|
||||
return mt;
|
||||
return r;
|
||||
}
|
||||
|
||||
static struct MT *
|
||||
default_mt(void)
|
||||
{
|
||||
return &rand_start(&default_rand)->mt;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
|
@ -363,6 +368,9 @@ get_rnd(VALUE obj)
|
|||
static rb_random_t *
|
||||
try_get_rnd(VALUE obj)
|
||||
{
|
||||
if (obj == rb_cRandom) {
|
||||
return rand_start(&default_rand);
|
||||
}
|
||||
if (!rb_typeddata_is_kind_of(obj, &random_data_type)) return NULL;
|
||||
return DATA_PTR(obj);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue