Tinyurl-style unique code: potential algorithm to prevent collisions

前端 未结 6 1960
梦如初夏
梦如初夏 2020-12-16 05:18

I have a system that requires a unique 6-digit code to represent an object, and I\'m trying to think of a good algorithm for generating them. Here are the pre-reqs:

6条回答
  •  爱一瞬间的悲伤
    2020-12-16 05:52

    Any prime number which is not a factor of the length of the sequence should be able to span the sequence without repeating. For 64000000, that means you shouldn't use 2 or 5. Of course, if you don't want them to be generated consecutively, generating them 2 or 5 apart is probably also not very good. I personally like the number 73973!

提交回复
热议问题