Ruby program to generate random numbers

To generate Random number in ruby we will use rand() method

#input upper and lower limits
puts "Enter Max number"
max=gets.chomp.to_i
puts "Enter Min number"
min=gets.chomp.to_i

#generate and print the random numbers
#between the given lower and upper limit
puts "The random numbers are..."
puts rand(min..max)
puts rand(min..max)
puts rand(min..max)
puts rand(min..max)
puts rand(min..max)

 

Output

Enter Max number
 40
Enter Min number
 20
The random numbers are...
28
26
22
37
31

 


Subscribe For Daily Updates

Flutter Questions
Android Questions