Ask HN: Best practices for creating unique IDs

https://news.ycombinator.com/item?id=1211799
by Rust • 16 years ago
7 6 16 years ago

Would you use your database's "auto increment" function, GUID function (if any), or simply assign a randomized alphanumeric string of N characters? Each method has pros and cons, but I have never been able to really settle on one. Lately I've been using random generation on the assumption that a sufficiently large number of characters (say, 32) makes the risk of duplication nearly non-existent - but not impossible.

When you've written something from scratch, which method have you most commonly used? I'm more interested in security than readability, but I can't find any data suggesting one method over another aside from the possibility of guessing an auto-incremented field.

Related Stories

Loading related stories...

Source preview

news.ycombinator.com