Ruby program for random number between two numbers



Write a Ruby program for random number between two numbers

class RandomNumber
  def calculateRandomNumber
     print "Enter the starting range: "
     start_num = gets.chomp.to_i
     print "Enter the ending range: "
     end_num = gets.chomp.to_i
     random_num = Random.new.rand(start_num..end_num)
     print "Random number is #{random_num}"
  end
end

p = RandomNumber.new 
p.calculateRandomNumber

Output:


Enter the starting range:  10
Enter the ending range:  100
Random number is 66


No comments:

Post a Comment