[erlang-questions] Replacing erlang:now/0 for getting a unique number

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Fri Sep 18 12:00:23 CEST 2015


On Fri, Sep 18, 2015 at 9:24 AM, zxq9 <zxq9@REDACTED> wrote:

> EventStamp = {monotonic_time(), unique_integer([monotonic])}.


This can also repeat! monotonic_time() starts at the same point whenever
the Erlang system reboots:

-module(z).
-export([t/0]).

t() ->
    io:format("~p~n", [erlang:monotonic_time()]),
    ok.

tiefling:~ jlouis$ for i in $(jot 10 1 10) ; do erl -noshell -s z t -s
erlang halt; done
-576460751926879092
-576460751926869976
-576460751923585212
-576460751924209286
-576460751925308499
-576460751926073063
-576460751927201176
-576460751927514165
-576460751927189332
-576460751925751652

So the more you restart the system, the grater risk of it repeating. You
probably want to use erlang:system_time().


-- 
J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150918/10cb10b1/attachment.htm>


More information about the erlang-questions mailing list