From: David Alan Black Date: 2004-03-07T03:57:00+09:00 Subject: Re: random range Hi -- On Sun, 7 Mar 2004, Joel VanderWerf wrote: > > > 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 > > Wouldn't size be infinite in this case? > > Now, if you wanted a non-uniform random distribution, it would be > possible. But how do you uniformly choose from an infinite set? Right -- I now see what you mean. I had Array tunnel-vision. David -- David Alan Black Associate Professor Department of Communication Seton Hall University blackdav@shu.edu http://pirate.shu.edu/~blackdav