summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
Diffstat (limited to 'array.c')
-rw-r--r--array.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/array.c b/array.c
index b265d6ac79..42bda2f444 100644
--- a/array.c
+++ b/array.c
@@ -2952,9 +2952,11 @@ rb_ary_shuffle(VALUE ary)
static VALUE
rb_ary_choice(VALUE ary)
{
- long i = RARRAY_LEN(ary);
- long j = genrand_real()*i;
+ long i, j;
+ i = RARRAY_LEN(ary);
+ if (i == 0) return Qnil;
+ j = genrand_real()*i;
return RARRAY_PTR(ary)[j];
}