ewallet
ewallet copied to clipboard
Always seed the random generator before Enum.rand/:rand/
Erlang by default do not use cryptographically strong seed for its random generator. This can result in generating a random number that could be predicted. This also applies to Enum.random
, as it also use :rand
internally.
See also https://hashrocket.com/blog/posts/the-adventures-of-generating-random-numbers-in-erlang-and-elixir
Additionally, all use of :random
is a no-no:
Pyxis ~ $ erl
Erlang/OTP 21 [erts-10.3.2] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [hipe]
Eshell V10.3.2 (abort with ^G)
1> random:uniform().
0.4435846174457203
2>
User switch command
--> q
Pyxis ~ $ erl
Erlang/OTP 21 [erts-10.3.2] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [hipe]
Eshell V10.3.2 (abort with ^G)
1> random:uniform().
0.4435846174457203
2>