[erlang-questions] Use of uuidgen with a mnesia application

Paul Fisher <>
Fri Jun 6 17:35:44 CEST 2008

On Fri, 2008-06-06 at 11:25 -0400, Andy Gross wrote:
> You can also use the following method for generating unique identifiers:
> 1> crypto:start().
> ok
> 2> <<I:160/integer>> = crypto:sha(term_to_binary({make_ref(), now()})).
> <41,13,88,29,5,111,251,80,169,13,157,98,38,200,99,138,10,
>   166,160,63>>
> 3> UUIDString = erlang:integer_to_list(I, 16).
> "4EDB9BAAB77AF8612C14390672C9D9B9BFB3F32A"
> 4>

That is not guaranteed to be unique.  make_ref() starts over each time
the node restarts, so the uniqueness depends on two nodes not generating
at the same microsecond (local clock perspective wise, that is.)
Ultimately, this is only slightly better than using the value of now()
directly.  (uuid values work similar to this, but have some number of
bits drawn from a random source to salt the result.)

If you want to have this type of unique identifier, you would use
whatever the crypto interface was to access random number generator.
uuid values have the benefit of being able to use the embedded MAC
address to tie the id back to the machine generating it (which come in
handy in clusters of nodes.)


More information about the erlang-questions mailing list