mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* random.c (Init_Random): add Random::DEFAULT.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b80d5f14df
commit
a4c0f7dfae
3 changed files with 24 additions and 1 deletions
|
@ -1,3 +1,7 @@
|
|||
Tue Aug 3 21:16:03 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* random.c (Init_Random): add Random::DEFAULT.
|
||||
|
||||
Tue Aug 3 21:01:10 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* hash.c (rb_check_hash_type): added.
|
||||
|
|
9
random.c
9
random.c
|
@ -329,7 +329,12 @@ random_mark(void *ptr)
|
|||
rb_gc_mark(((rb_random_t *)ptr)->seed);
|
||||
}
|
||||
|
||||
#define random_free RUBY_TYPED_DEFAULT_FREE
|
||||
static void
|
||||
random_free(void *ptr)
|
||||
{
|
||||
if (ptr != &default_rand)
|
||||
xfree(ptr);
|
||||
}
|
||||
|
||||
static size_t
|
||||
random_memsize(const void *ptr)
|
||||
|
@ -1232,6 +1237,8 @@ Init_Random(void)
|
|||
rb_define_private_method(rb_cRandom, "state", random_state, 0);
|
||||
rb_define_private_method(rb_cRandom, "left", random_left, 0);
|
||||
rb_define_method(rb_cRandom, "==", random_equal, 1);
|
||||
rb_define_const(rb_cRandom, "DEFAULT",
|
||||
TypedData_Wrap_Struct(rb_cRandom, &random_data_type, &default_rand));
|
||||
|
||||
rb_define_singleton_method(rb_cRandom, "srand", rb_f_srand, -1);
|
||||
rb_define_singleton_method(rb_cRandom, "rand", rb_f_rand, -1);
|
||||
|
|
|
@ -415,4 +415,16 @@ END
|
|||
assert_equal(r1, r2)
|
||||
}
|
||||
end
|
||||
|
||||
def test_default
|
||||
r1 = Random::DEFAULT.dup
|
||||
r2 = Random::DEFAULT.dup
|
||||
3.times do
|
||||
x0 = rand
|
||||
x1 = r1.rand
|
||||
x2 = r2.rand
|
||||
assert_equal(x0, x1)
|
||||
assert_equal(x0, x2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue