From: Charles Comstock Date: 2004-03-07T16:49:39+09:00 Subject: Re: random range > > No Enumerable#size. Try: > > module Enumerable > ## Return a random element, or nil if empty. > def rand > i = 1 > ret = nil > each do |el| > if Kernel.rand(i) == 0 > ret = el > end > i += 1 > end > return ret > end > end > > Umm I don't think that is a uniform distribution, not to mention the fact that you don't break out of the each if it succeeds. Hmm we definitely should allow integer array's, but I am seeing more and more potential problems with generic Enumerables. Maybe have it be another include module, but demand a way to initialize a value anywhere in an enumerable, not just with each / yield. With integer ranges you just need the upper/lower bound, but if your defining each object with succ, it causes issues I think. Charles Comstock