erlang-uuid icon indicating copy to clipboard operation
erlang-uuid copied to clipboard

random data source

Open archaelus opened this issue 15 years ago • 0 comments

The uuid library uses the 'random' library to generate random numbers. Unfortunately this library defaults to using a constant seed and so the sequence of uuids generated by a new process calling uuid() is always the same.

 spawn(fun() -> io:format("~n~p Generated unique id ~p~n", [self(), uuid:v4()]) end).

The above shell code shows what I mean if executed a few times.

A better source for random data in OTP is the crypto module - crypto:rand_bytes/1 uses the openssl psuedo_rand function to generate random data, returned as a binary.

archaelus avatar Nov 03 '09 12:11 archaelus