红宝石 |随机 random_number()函数
Random#random_number() : random_number()是一个 Random 类方法,它检查从原始随机字节中返回一个随机数
Syntax: Random.random_number()
Parameter: Random values
Return: random number from raw random bytes
示例 #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