📜  红宝石 |随机种子()函数

📅  最后修改于: 2022-05-13 01:54:24.401000             🧑  作者: Mango

红宝石 |随机种子()函数

Random#seed() : seed()是一个 Random 类方法,它返回用于初始化生成器的种子值

示例 #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