At work thres a legacy "common" DLL, which held a helper function that's incharge of creating Slugs, it takes an MD5 of the current time stamp UTC, removing non-URLable chars, and taking the first N chars that remain then

Ngl I was impressed at first at it, but then I thought, its Uniqueness isnt guaranteed

But then again I thought, the uniqueness can be tested via a call given it's indexed anyway in DB so O(1), and if non-unique, just re-call the function. Even in the worst case scenario the hits won't be that many anyway

I didnt change the code, tho at first I was inclined to given my "it isnt proven-unique" stance but am wondering, if this is a good approach
While coolish, it seems wrong in the back of my mind somehow...

  • 0
    I guess it's prolly quite alright. Although I also feel filthy even reading about it.

    Instead I'd prolly have used a db sequence or a DB row ID, or a timestamp. If predictability is an issue - shuffle its bits in a predefined sequence, not losing any values. Eventual values will seem random, although definitely unique [because based on an always incrementing algo].
Add Comment