What is a proper length of random code used as mys

2019-09-08 07:47发布

I assign each mysql row with a random code. Only alphanumeric lowercase characters and numbers are used.

These random codes are used for SELECT and JOIN queries.

Most often I use length of 24 characters which gives roughly 2.2x10^37 available combinations.

What is the perfect random code length that does not require checking for duplicates while being certain no collisions will occur but also keeping query result time to minimum?

Note: On big tables I use INDEX for the random code column of length 24.

标签: php mysql random
2条回答
Ridiculous、
2楼-- · 2019-09-08 08:22

It is not possible to generate a random code which might not be duplicated, therefore you must always check for duplicates and there is no "perfect random code length".

查看更多
别忘想泡老子
3楼-- · 2019-09-08 08:27

The nature of a RANDOM code is that you can never be certain it will not be duplicated. You can guarantee there wont be a duplicate if you use a sequential number & if you are doing that you might as well use the AUTO INCREMENT option with a sufficiently large integer.

http://dilbert.com/strip/2001-10-25

查看更多
登录 后发表回答