generate a random number between 0 and 1 in ruby

To generate a random number between 0 and 1 in Ruby, you can use the rand method which returns a float between 0 and 1. Here's an example:

main.rb
random_number = rand
puts "Random number between 0 and 1: #{random_number}"
76 chars
3 lines

This will output something like:

main.rb
Random number between 0 and 1: 0.8263651663743646
50 chars
2 lines

related categories

gistlibby LogSnag