Skip to content
Related Articles

Related Articles

Ruby | Random seed() function

Improve Article
Save Article
Like Article
  • Last Updated : 17 Dec, 2019

Random#seed() : seed() is a Random class method which returns seed value used to initialize the generator

Syntax: Random.seed()

Parameter: Random values

Return: seed value used to initialize the generator

Example #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"

Output :

Random seed form : 14627199005973434753488768581471776591

Random seed form : 109687128738022354367166747684231621010

Example #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"

Output :

Random seed form : 11386853110334908739001826239583965416

Random seed form : 191743863873657838482754700438995226369

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!