Ruby srand returns the previous seed
srand
is a method on Kernel that seeds the pseudo random number generator. It takes a new seed as an argument or calls Random.new_seed
if you don't pass an argument. What's interesting about it is that it returns the old seed. This has the effect of return a new large random number every time you call srand
.
Which can come in handy if you're playing some Ruby golf and need to generate a huge random number in as few characters as possible.
H/T Dillon Hafer
Tweet