i’ve been working on an idea and a need a simple short code id, i didnt want to pull in a library just for that, i thought sqids would be an overkill for my usage.
so i looked some uuidv4 generation code and worked on something like the following(that would be just the first part of the uuidv4):
In a distributed environment, that is, between multiple Erlang nodes, erlang:unique_integer/1 does not guarantee global uniqueness. Each node maintains its own counter, and conflicts can occur if multiple nodes generate unique integers at the same time.
for my use case it’s not relevant, those ids just need to avoid conflict in a local context. the sloppy solution with the unique_integer is more than enough for me.
but thanks for the suggestion, i gonna check the library.
Also note that unique_integers are unique only for the lifetime of a node. That is, if you restart a node, there may be (or rather, there are likely to be) clashes with unique integers produced by previous runs of the same node. That is to say, if your supposedly-unique identifiers are in some way relevant outside of a running node, unique_integer is not a safe bet.
We’ve been using identifiers based on {erlang:system_time(millisecond), erlang:unique_integer([positive])} which for us was light enough and safe enough.