Generating unique ids in Mnesia

Hakan Mattsson hakan@REDACTED
Thu Aug 18 16:46:32 CEST 2005


On Thu, 18 Aug 2005, Joel Reymont wrote:

JR> Folks,
JR> 
JR> I need to maintain a table of players in Mnesia and I would like to assign
JR> players a unique id when they are added. Right now I generate a tuple of
JR> {timestamp hash, pid hash} and then hash that once more to get a unique
JR> id.
JR> 
JR> Is there an easier way to do this in Mnesia? The ids can be sequential or
JR> random, they just can't repeat themselves as the table is a set. I guess
JR> I'm looking for something like a max aggregator on a Mnesia column.

You can use

  erlang:now()

or 

  {node(), erlang:now()}

in a multi node system.

/Håkan


More information about the erlang-questions mailing list