Last active
August 29, 2015 14:02
-
-
Save eiri/9914ff58108e427b303e to your computer and use it in GitHub Desktop.
uuid v4 in erlang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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