Initialise a random number generator with a seed and generate five decimal values. Reset the seed and produce the same values.
ruby srand(12345)
first = (1..5).collect {rand}
srand(12345)
second = (1..5).collect {rand}
puts first == second
srand(12345)
first = (1..5).collect {rand}
srand(12345)
second = (1..5).collect {rand}
puts first == second
Submit a new solution for
ruby
There are 17 other solutions in
additional languages (
clojure,
cpp,
csharp,
erlang ...)