當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Ruby Random seed()用法及代碼示例


Random#seed():seed()是一種隨機類方法,該方法返回用於初始化生成器的種子值

用法:Random.seed()

參數:隨機值


返回:用於初始化生成器的種子值

示例1:

# Ruby code for Random.seed() method 
  
# declaring Random value 
date_a = Random.new() 
  
# declaring Random value 
date_b = Random.new() 
  
# seed value 
puts "Random seed form : #{date_a.seed}\n\n"
  
puts "Random seed form : #{date_b.seed}\n\n"

輸出:

Random seed form : 14627199005973434753488768581471776591

Random seed form : 109687128738022354367166747684231621010

示例2:

# Ruby code for Random.seed() method 
  
# declaring Random value 
date_a = Random.new.seed 
  
# declaring Random value 
date_b = Random.new() 
  
# seed value 
puts "Random seed form : #{date_a}\n\n"
  
puts "Random seed form : #{date_b.seed}\n\n"

輸出:

Random seed form : 11386853110334908739001826239583965416

Random seed form : 191743863873657838482754700438995226369



相關用法


注:本文由純淨天空篩選整理自mayank5326大神的英文原創作品 Ruby | Random seed() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。