Ruby Random random_number()函数
Random#random_number() : random_number() 是一个随机类方法,它检查从原始随机字节返回一个随机数。
语法。Random.random_number()
参数。随机值
返回:从原始随机字节的随机数
例子 #1 :
# Ruby code for Random.random_number() method
# loading library
require 'securerandom'
# declaring Random value
date_a = SecureRandom.random_number
# declaring Random value
date_b = SecureRandom.random_number
# random_number value
puts "Random random_number form : #{date_a}\n\n"
puts "Random random_number form : #{date_b}\n\n"
输出:
Random random_number form : 0.06094009368827358
Random random_number form : 0.23398922898567265
例子 #2 :
# Ruby code for Random.random_number() method
# loading library
require 'securerandom'
# declaring Random value
date_a = SecureRandom.random_number(10)
# declaring Random value
date_b = SecureRandom.random_number(200)
# random_number value
puts "Random random_number form : #{date_a}\n\n"
puts "Random random_number form : #{date_b}\n\n"
输出:
Random random_number form : 6
Random random_number form : 82