Hi --

On Sun, 7 Mar 2004, Hal Fulton wrote:

> Charles Comstock wrote:
> > Why doesn't rand take an integer range and then generate a random number 
> > in between the two?
> > 
> > Example:
> >     rand(5..10) -> a random number from 5 to 10 including 10
> >     rand(5...10) -> a random number from 5 to 10 excluding 10
> > 
> > That or maybe add rand to range so it picks a random item out of the 
> > range.  For that matter why doesn't Array/Hash have a method to return a 
> > random element?
> > That way [1,2,4].rand and (5..10).rand would work.
> 
> Charles,
> 
> We were talking about this in IRC. Maybe you were one of those? :)
> 
> Someone suggested allowing not just rand(Fixnum) and rand(Range)
> but in general rand(Enumerable).
> 
> Someone else said: That's kind of "overloading" the meaning of rand.
> Well, I can see that might not be appropriate.

I'm the one who said that, and I was actually referring to the
rand(range) idea :-)  I don't know if overloading is the right word.
It just had the feel of kind of sugarizing this:

  rand(x) + y

into this:

  rand(x..y)

I'm not strongly against it, though.  Given that rand(x) itself is, in
effect, bound by a range, it's certainly not a big stretch to specify
that range as a Range.


David

-- 
David A. Black
dblack / wobblini.net