Skip to content

Instantly share code, notes, and snippets.

@eiri
Last active August 29, 2015 14:02
Show Gist options
  • Save eiri/9914ff58108e427b303e to your computer and use it in GitHub Desktop.
Save eiri/9914ff58108e427b303e to your computer and use it in GitHub Desktop.
uuid v4 in erlang
uuid() ->
<<A:32, B:16, C:16, D:16, E:48>> = crypto:rand_bytes(16),
Fmt = "~8.16.0b-~4.16.0b-4~3.16.0b-~4.16.0b-~12.16.0b",
Str = io_lib:format(Fmt, [A, B, C band 16#0fff, D band 16#3fff bor 16#8000, E]),
list_to_binary(Str).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment