Mike Hall <mghallNO / enteract.SPAMcom> wrote in message news:<404a75a3$0$3080$61fed72c / news.rcn.com>...
> Mark Hubbart  wrote:
> 
> >I like the idea of allowing Kernel.rand(range), for reasons already 
> >presented by others. Kernel.rand(array) seems a little iffy to me, but 
> >that's me. :)
> 
> I agree, FWIW.
> 
> A thought:  what about a "Random" module, somewhat like the Enumerable module.
> We can include it where we want it.
> 
> Also, there are times when I don't necessarily want a uniform random "pick" from an Array, but need a certain weighting.  The module could help provide that.
> 
> Whatever.

What about this...
Or, what would the dangers be?

class Range
  def random
     r = self.to_a
     r[ rand(r.size) ]
  end
end

(5..10).random

class Array
  def random
     self[ rand(size) ]
   end
end

[2,4,6,8].random