Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
27 lines (17 sloc) 1.1 KB
layout title date comments categories
Elixir: Seed the Random
2014-02-03 00:45:28 -0500
erlang elixir random seed

Just a quick note for something I was just reminded of the hard way:

Always seed your random values.

If you're using the Enum::Shuffle/1 function, for example, pay attention to the part of the documentation that says:

Notice that you need to explicitly call :random.seed/1 and set a seed value for the random algorithm. Otherwise, the default seed will be set which will always return the same result.

Do as the documentation suggestions and use this:


Otherwise, you will get the same results returned to you a thousand times.

Trust me. I know. I've lived it. Save yourself.

(Special thanks to @sfalcon for reminding me...)

Update August 11, 2015: is deprecated in Erlang as of v18.0. The text of this post has been updated to change to the :os.timestamp command to set the random seed.

You can’t perform that action at this time.