Logo

Programming-Idioms

History of Idiom 69 > diff from v25 to v26

Edit summary for version 26 by :
[Ruby] removed comment

Version 25

2016-04-07, 22:14:57

Version 26

2016-04-12, 21:27:01

Idiom #69 Seed random generator

Use seed s to initialize a random generator.

If s is constant, the generator output will be the same each time the program runs. If s is based on the current value of the system clock, the generator output will be different each time.

Idiom #69 Seed random generator

Use seed s to initialize a random generator.

If s is constant, the generator output will be the same each time the program runs. If s is based on the current value of the system clock, the generator output will be different each time.

Code
r = Random.new(s)
Code
r = Random.new(s)
Comments bubble
Ruby's rand method will be seeded with a random number like 115032730400174366788466674494640623225 by default, far superior to system clock.
Doc URL
http://ruby-doc.org/core-2.2.3/Random.html#method-c-new
Doc URL
http://ruby-doc.org/core-2.2.3/Random.html#method-c-new