Skip to content

Instantly share code, notes, and snippets.

@zeroeth
Created November 3, 2012 20:08
Show Gist options
  • Select an option

  • Save zeroeth/4008552 to your computer and use it in GitHub Desktop.

Select an option

Save zeroeth/4008552 to your computer and use it in GitHub Desktop.
srand
srand(100)
10.times.collect{ rand(5) }
[0, 0, 3, 0, 2, 4, 2, 2, 2, 2]
10.times.collect{ rand(5) }
[1, 0, 0, 4, 3, 4, 2, 0, 3, 1]
# repeat, see same creation again with seed 100
srand(100)
10.times.collect{ rand(5) }
[0, 0, 3, 0, 2, 4, 2, 2, 2, 2]
10.times.collect{ rand(5) }
[1, 0, 0, 4, 3, 4, 2, 0, 3, 1]
# you as a number
your_face = "laurel".split(//).collect{|letter| letter.ord}.join.to_i
srand(your_face)
10.times.collect{ rand(5) }
[4, 4, 4, 1, 2, 4, 2, 4, 4, 0]
10.times.collect{ rand(5) }
[4, 2, 2, 1, 0, 0, 3, 4, 2, 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment