Skip to content

Instantly share code, notes, and snippets.

@eiri
Last active February 17, 2016 14:51
Show Gist options
  • Save eiri/417af4243fb00c73ecc4 to your computer and use it in GitHub Desktop.
Save eiri/417af4243fb00c73ecc4 to your computer and use it in GitHub Desktop.
Generate random unique keys with erlang's reference
make_random_ref_key() ->
<<X:264/big-unsigned-integer>> = term_to_binary(make_ref()),
[Key] = io_lib:format("~66.16.0b", [X]),
{ok, Key}.
make_random_md5_key() ->
<<X:128/big-unsigned-integer>> = crypto:hash(md5, term_to_binary(make_ref())),
[Key] = io_lib:format("~32.16.0b", [X]),
{ok, Key}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment