Unique, unpredictable, 12 digit, integer id

前端 未结 7 1100
被撕碎了的回忆
被撕碎了的回忆 2021-01-13 06:56

How would I go about generating this... I want to keep my primary key sequential and have a 12 digit unique pin generated for each new object added to the database.

7条回答
  •  遥遥无期
    2021-01-13 07:25

    You want two things

    1. Uniqueness
    2. Incremental

    If you want both the things from same sequence you will run out of luck (literally) Uniqueness is guaranteed by having large sample space + random + check-unique. Which means, the actual number could be anywhere in between the sample space.

    But if you want unique + incremental property, you are dividing sample space by 2. In 64 tries you would have reduced a 64 bit int sample space to 1 bit sample space.

    Good luck !

提交回复
热议问题