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
相關用法
- Ruby Random new()用法及代碼示例
- Scala Random ==()用法及代碼示例
- Ruby Random hex()用法及代碼示例
- Ruby Random srand()用法及代碼示例
- Ruby Random rand()用法及代碼示例
- Ruby Random random_bytes()用法及代碼示例
- Ruby Random urlsafe_base64()用法及代碼示例
- Ruby Random new_seed()用法及代碼示例
- Ruby Random seed()用法及代碼示例
- Ruby Random uuid()用法及代碼示例
- Ruby Random base64()用法及代碼示例
- Ruby Random bytes()用法及代碼示例
- Ruby Set add?用法及代碼示例
注:本文由純淨天空篩選整理自mayank5326大神的英文原創作品 Ruby | Random random_number() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。