Random
Published Jul 27, 2021Updated Sep 9, 2021
Contribute to Docs
The 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.
Example
# 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
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.