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

Alexander Lamb <>
Fri Jun 6 16:43:34 CEST 2008


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
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",

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.
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)?


Alexander Lamb
Founding Associate

4 ch. de la Tour de Champel
1206 Geneva

Tel:  022 347 77 37
Fax: 022 347 77 38


More information about the erlang-questions mailing list