-module(uuid). -export([v4/0]). -export([v7/0]). % used for test by meck -export([get_time/0, strong_rand/1]). v4() -> <> = uuid:strong_rand(16), to_str([<>, <>, <<4:4, C:12>>, <<2:2, D:14>>, <>]). v7() -> Timestamp = uuid:get_time(), <> = <>, <> = uuid:strong_rand(10), to_str([<>, <>, <<7:4, C:12>>, <<2:2, D:14>>, <>]). to_str([_, _, _, _, _] = Parts) -> UUId = lists:join(<<"-">>, [binary:encode_hex(P) || P <- Parts]), string:lowercase(UUId). get_time() -> os:system_time(millisecond). strong_rand(Size) -> crypto:strong_rand_bytes(Size).