[erlang-questions] Use of uuidgen with a mnesia

Jacob Perkins <>
Fri Jun 6 17:45:22 CEST 2008


Another way to generate uuids is to have a permanent gen_server process
generate random strings. Having a long running process ensures good
randomness since random:seed uses the process dictionary. Below is a random
alphanumeric string generation function that you could plug in to a
gen_server that calls random:seed at init time.

random(Size) ->
Chars = lists:seq($0, $9) ++ lists:seq($A, $Z) ++ lists:seq($a, $z),
N = length(Chars),
F = fun(_, S) -> [lists:nth(random:uniform(N), Chars) | S] end,
lists:foldl(F, [], lists:seq(1, Size)).


Date: Fri, 6 Jun 2008 11:25:32 -0400
> From: Andy Gross <>
> Subject: Re: [erlang-questions] Use of uuidgen with a mnesia
>        application
> To: 
> Message-ID: <>
> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
>
>
> 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>
>
> - Andy
>
> On Jun 6, 2008, at 11:12 AM, Paul Fisher wrote:
>
> > On Fri, 2008-06-06 at 17:06 +0200, Alexander Lamb wrote:
> >> I see, but it means you wrote a piece of code in C (probably) to call
> >> uuid on the underlying system?
> >>
> >> (maybe it's the word "drive" that I didn't fully understand.
> >
> > Yes, a linked-in erlang driver, written in C.  Once you write the
> > first
> > one it is not so bad after that.
> >
> >
> > --
> > paul
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080606/6ca80ee5/attachment.html>


More information about the erlang-questions mailing list