On Mar 6, 2004, at 10:29 AM, David A. Black wrote:

> Hi --
>
> On Sun, 7 Mar 2004, Joel VanderWerf wrote:
>
>> Hal Fulton wrote:
>>> Someone suggested allowing not just rand(Fixnum) and rand(Range)
>>> but in general rand(Enumerable).
>>
>> Would be tricky for general Enumerables...
>>
>>    class Seq
>>      include Enumerable
>>      def each
>>        i = 0
>>        loop do
>>          yield i
>>          i += 1
>>        end
>>      end
>>    end
>
> I'm not quite following (?) -- I think the original idea was
> something like:
>
>   module Enumerable
>     def rand
>       to_a[Kernel.rand(size)]
>     end
>   end

Please don't redefine a Kernel method. I think that's a Bad Idea(tm). 
Why not use #random instead?

     >> module Enumerable
     >>   def random
     >>     to_a[rand(size)]
     >>   end
     >> end
    => nil
     >> [1,4,6].random
    => 4
     >> [1,4,6].random
    => 6

It would look like an attribute rather than a method... that is, it 
would fit in with #first and #last.

OTOH, I also like the other idea, using #pick and #pick!. #random! just 
doens't make sense, and one method for plucking a random element out of 
an array would be nice.

--Mark