summaryrefslogtreecommitdiff
path: root/random.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-07-04 04:17:26 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-07-04 04:17:26 +0000
commit4f51d814183316c3e97da1dc13cf6945b5a76f2f (patch)
tree3ab2686a359f6cbdda8446d7382f9aa541c2490a /random.c
parent5a8bfc39f132708bcf3ee2970e9f55ee6d101b65 (diff)
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@810 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'random.c')
-rw-r--r--random.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/random.c b/random.c
index 65fc69e..32cb525 100644
--- a/random.c
+++ b/random.c
@@ -130,11 +130,15 @@ rb_f_srand(argc, argv, obj)
}
static VALUE
-rb_f_rand(obj, vmax)
- VALUE obj, vmax;
+rb_f_rand(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
{
+ VALUE vmax;
long val, max;
+ rb_scan_args(argc, argv, "01", &vmax);
if (first) {
struct timeval tv;
@@ -148,9 +152,14 @@ rb_f_rand(obj, vmax)
/* fall through */
case T_BIGNUM:
return rb_big_rand(vmax, RANDOM_NUMBER);
+ case T_NIL:
+ max = 0;
+ break;
+ default:
+ max = NUM2LONG(vmax);
+ break;
}
- max = NUM2LONG(vmax);
if (max == 0) {
return rb_float_new(RANDOM_NUMBER);
}
@@ -164,5 +173,5 @@ void
Init_Random()
{
rb_define_global_function("srand", rb_f_srand, -1);
- rb_define_global_function("rand", rb_f_rand, 1);
+ rb_define_global_function("rand", rb_f_rand, -1);
}