Published Jul 27, 2021Updated Sep 9, 2021
Contribute to Docs
rand function will return a random number greater than or equal to 0 and less than the integer passed to the function. If an argument is not passed to the function, the return value is a random number between 0 and 1.
# When no argument is passed, the result is a random number between 0 and 1.puts rand();# Output example: 0.5
# When an argument is passed, the result is a random number between 0 and the argument.puts rand(10);# Output example: 6
Learn Ruby on Codecademy
Learn Ruby on RailsLearn the basics of building applications with this convenient and powerful web development framework.