On Jun 9, 9:35 ¨Âí¬ ÔéÈõîôåò ¼ÔéíÈõî®®®Àîã®òò®ãïí÷òïôåº > David Stanislaus wrote: > > How would you create a random number generator thats limited to a > > specific rang? say > > > 1930 - 1950 > > > Thanks > > Observe that Kernel#rand accepts an argument. If present and not 0, then > rand returns numbers >= 0.0 and < the argument. So > > x = rand(20) > > will always return a number n such that 0.0 <= n < 20. All you have to > do is add 1930 to it: > > x = 1930 + rand(20) Well if the desired range is 1930-1950 *inclusive*, then it should be: x = 1930 + rand(21) since there are 21 distinct values in the inclusive range. Or, more generally for inclusive boundaries: x = low + rand(high - low + 1) Eric ==== LearnRuby.com offers Rails & Ruby HANDS-ON public & ON-SITE workshops. Ruby Fundamentals Wkshp June 16-18 Ann Arbor, Mich. Ready for Rails Ruby Wkshp June 23-24 Ann Arbor, Mich. Ruby on Rails Wkshp June 25-27 Ann Arbor, Mich. Ruby Plus Rails Combo Wkshp June 23-27 Ann Arbor, Mich Please visit http://LearnRuby.com for all the details.