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

Alexander Lamb alexander.lamb@REDACTED
Fri Jun 6 17:53:52 CEST 2008


Yes, I agree it would be better.

Actually, there is a mistake in my code: it is necessary to add a  
lists:sublist(Result,36) because cmd returns the command with the  
trailing carriage return!

 From what I see by googling uuid erlang, it seems like this could be  
a welcome addition to the basic erlang package.

Alex

Le 6 juin 08 à 17:29, Anders Nygren a écrit :

> On Fri, Jun 6, 2008 at 9:43 AM, Alexander Lamb
> <alexander.lamb@REDACTED> wrote:
>> Hello,
>>
>> I need to generate ids to be used as mnesia keys which will be unique
>> not only withing a cluster of Erlang nodes but also globally (e.g.  
>> may
>> be read from a Java program).
>>
>> I initially thought of writing my own uuidgen function, but it seems
>> like reading the mac address of network interfaces can be rather
>> cumbersom depending on systems.
>>
>> So I decided to use uuidgen from the system and convert it to binary
>> (for efficiency).
>>
>> Is this the correct way of doing things:
>>
>> verify_guuid(Value) ->
>>       A = lists:nth(9,Value),
>>       B = lists:nth(14,Value),
>>       C = lists:nth(19,Value),
>>       case [A,B,C] of
>>               "---" -> true;
>>               _         -> false
>>       end.
>>
>> make_guuid() ->
>>       First = os:cmd("uuidgen -t"),
>>       case verify_guuid(First) of
>>               true    -> Result = First;
>>               false   -> Second = os:cmd("uuidgen"),
>>                                  case verify_guuid(Second) of
>>                                               true  -> Result =  
>> Second;
>>                                               false -> Result =  
>> "error",
>>                                                                 
>> throw({uuidgen_error,Second})
>>                                  end
>>       end,
>>       erlang:list_to_binary(Result).
>>
>> Now, the reason I have this cascade of case is because on Linux (our
>> Ubuntu servers) it recognizes the -t option to generate the uuid and
>> on MacOSX (our dev machines) it does not.
>
> Wouldn't it be "nicer" to use os:type/0 and os:version/0 to detect
> what system You are running on?
>
> /Anders
>
>> Call me crazy, but I never feel confortable about using a totally
>> random uuid to identity medical records that might be copied from
>> system to system, exported, etc... even if the probability of
>> collision is lower than that of a large asteroid hitting earth!
>>
>> What is your strategy for this (maybe this is a question to ask the
>> couchdb developers, since they use guuids to identify the documents)?
>>
>> Thanks,
>>
>> Alex
>> --
>> Alexander Lamb
>> Founding Associate
>> RODANOTECH Sàrl
>>
>> 4 ch. de la Tour de Champel
>> 1206 Geneva
>> Switzerland
>>
>> Tel:  022 347 77 37
>> Fax: 022 347 77 38
>>
>> http://www.rodanotech.ch
>>
>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>
>




More information about the erlang-questions mailing list