Life's random bits By b1thunt3r (aka Ishan Jain)…
Unique ID

Unique ID

Ishan jain
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.

  1. Use UNIX timestamp in milliseconds
  2. Use DateTime.Now.ToBinary() in C#
  3. Use a database which keeps track of used identifiers
  4. 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();