On 01.03.2010 20:21, Reiichi Tyrael wrote: > I must create a little game; the one who play it must choose 2 numbers, > the beginning and the end of a range, and the program generate a secret > random number within that range, so the player must guess it! > But the problem is...how do I generate a random number? > I though at something like this: > > number_to_guess = rand(n1..n2) > > but it give me the error message "in `rand': can't convert Range into > Integer (TypeError)" > > What can I do? Thanks! rand only accepts an integer which will make it produce values in the range 0...n (exclusive). So you can do: irb(main):001:0> low, high = 12, 56 => [12, 56] irb(main):002:0> r = low + rand(high - low) => 54 Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/