summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-03 01:51:26 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-03 01:51:26 +0000
commit6decf411c6f8fd6778d8d4326a8dd8a0e2c09dcd (patch)
treee75fb0ead125ae468a85d7affceca9d2a62b9288
parenta9aeb765c5b6681063682d67df75df96af5860b0 (diff)
* random.c (random_rand): raise ArgumentError on nil, as the
documentation implies. [ruby-core:29075] * random.c (rb_f_rand): mentioned the case of when max is nil. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--random.c5
-rw-r--r--test/ruby/test_rand.rb1
3 files changed, 10 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 5273505841..fc543a662f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sat Apr 3 10:51:10 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * random.c (random_rand): raise ArgumentError on nil, as the
+ documentation implies. [ruby-core:29075]
+
+ * random.c (rb_f_rand): mentioned the case of when max is nil.
+
Sat Apr 3 06:56:11 2010 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
* array.c (rb_ary_product): Accept a block [ruby-core:29045]
diff --git a/random.c b/random.c
index 9e35861fad..6efefe6232 100644
--- a/random.c
+++ b/random.c
@@ -989,7 +989,6 @@ random_rand(int argc, VALUE *argv, VALUE obj)
int excl = 0;
if (argc == 0) {
- zero_arg:
return rb_float_new(genrand_real(&rnd->mt));
}
else if (argc != 1) {
@@ -997,7 +996,7 @@ random_rand(int argc, VALUE *argv, VALUE obj)
}
vmax = argv[0];
if (NIL_P(vmax)) {
- goto zero_arg;
+ v = Qnil;
}
else if (TYPE(vmax) != T_FLOAT && (v = rb_check_to_integer(vmax, "to_int"), !NIL_P(v))) {
v = rand_int(&rnd->mt, vmax = v, 1);
@@ -1098,7 +1097,7 @@ random_equal(VALUE self, VALUE other)
* rand(max=0) => number
*
* Converts <i>max</i> to an integer using max1 =
- * max<code>.to_i.abs</code>. If the result is zero, returns a
+ * max<code>.to_i.abs</code>. If _max_ is +nil+ the result is zero, returns a
* pseudorandom floating point number greater than or equal to 0.0 and
* less than 1.0. Otherwise, returns a pseudorandom integer greater
* than or equal to zero and less than max1. <code>Kernel::srand</code>
diff --git a/test/ruby/test_rand.rb b/test/ruby/test_rand.rb
index 97ac8147bd..157f542dea 100644
--- a/test/ruby/test_rand.rb
+++ b/test/ruby/test_rand.rb
@@ -207,6 +207,7 @@ class TestRand < Test::Unit::TestCase
assert_raise(ArgumentError, '[ruby-dev:39166]') { r.rand(0..-1) }
assert_raise(ArgumentError, '[ruby-dev:39166]') { r.rand(0.0...0.0) }
assert_raise(ArgumentError, '[ruby-dev:39166]') { r.rand(0.0...-0.1) }
+ assert_raise(ArgumentError, bug3027 = '[ruby-core:29075]') { r.rand(nil) }
end
def test_random_seed