Hacker News new | past | comments | ask | show | jobs | submit login

ShortUUID looks like fun. I usually just get a UUID4 and grab the last section of the generated UID.

Something like str(uuid.uuid4()).split("-")[4]

I'd like to say that I then do a duplicate check, but I don't think I've ever had a collision, so I'm not actually 100% true that I do.

Best case, you've saved me a database query, worst case, you've saved me a potentially painful Exception.

Danke.




It's pretty unlikely that you'll get a collision if you grab enough digits, but hex is only 16 digits. One easily has 62ish characters available (ShortUUID removes lookalikes so people can still read and type the codes), so why not squeeze as much randomness in them as you can? That's pretty much why I wrote it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: