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

David Mercer <>
Fri Jun 6 17:52:33 CEST 2008


On Friday, June 06, 2008, 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"

If you go with this approach, you need to handle leading zeroes.  Change
line 3 to:

3> lists:flatten(io_lib:fwrite("~40..0s", [erlang:integer_to_list(I, 16)])).

DBM




More information about the erlang-questions mailing list