Unique ID
There are times when you need some sort of unique identifier for some reason, and it can be hard to find a system that will have a very low collision risk.
After working on the problem for a while, I could find some ways to generate unique identifier.
- Use UNIX timestamp in milliseconds
- Use DateTime.Now.ToBinary() in C#
- Use a database which keeps track of used identifiers
- Or create a complicated algorithm
According to my analysis, the best and least CPU cycle eating method is to use time, either UNIX timestamp or DateTime in C#. So far a time machine has not been invented so it is hard to create a duplicate timestamp, and a millisecond is little time, it is hard to create a collision.
It looks like, at least PHP, Java and C# has libraries for unique id generation.
PHP:
uniqid();
C#:
System.Guid.NewGuid()
Java:
java.util.UUID.randomUUID();