зеркало из https://github.com/github/ruby.git
* random.c (random_equal): new method Random#==.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
bc0ea18dbd
Коммит
115c220b4d
|
@ -1,3 +1,7 @@
|
|||
Fri Jul 17 13:55:53 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* random.c (random_equal): new method Random#==.
|
||||
|
||||
Fri Jul 17 13:35:47 2009 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* ext/socket/init.c (rsock_getfamily): return AF_UNSPEC if getsockname
|
||||
|
|
21
random.c
21
random.c
|
@ -910,6 +910,26 @@ random_float(int argc, VALUE *argv, VALUE obj)
|
|||
return add_to_begin(beg, rb_float_new(r));
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* prng1 == prng2 -> true or false
|
||||
*
|
||||
* Returns true if the generators' states equal.
|
||||
*/
|
||||
static VALUE
|
||||
random_equal(VALUE self, VALUE other)
|
||||
{
|
||||
rb_random_t *r1, *r2;
|
||||
if (rb_obj_class(self) != rb_obj_class(other)) return Qfalse;
|
||||
r1 = get_rnd(self);
|
||||
r2 = get_rnd(other);
|
||||
if (!RTEST(rb_funcall2(r1->seed, rb_intern("=="), 1, &r2->seed))) return Qfalse;
|
||||
if (memcmp(r1->mt.state, r2->mt.state, sizeof(r1->mt.state))) return Qfalse;
|
||||
if ((r1->mt.next - r1->mt.state) != (r2->mt.next - r2->mt.state)) return Qfalse;
|
||||
if (r1->mt.left != r2->mt.left) return Qfalse;
|
||||
return Qtrue;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* rand(max=0) => number
|
||||
|
@ -991,6 +1011,7 @@ Init_Random(void)
|
|||
rb_define_method(rb_cRandom, "marshal_load", random_load, 1);
|
||||
rb_define_method(rb_cRandom, "state", random_state, 0);
|
||||
rb_define_method(rb_cRandom, "left", random_left, 0);
|
||||
rb_define_method(rb_cRandom, "==", random_equal, 1);
|
||||
|
||||
rb_define_singleton_method(rb_cRandom, "srand", rb_f_srand, -1);
|
||||
rb_define_singleton_method(rb_cRandom, "rand", rb_f_rand, -1);
|
||||
|
|
Загрузка…
Ссылка в новой задаче