PHP short unique ID generation using auto_increment?

后端 未结 8 1487
自闭症患者
自闭症患者 2021-02-04 17:14

I would like to generate a short, unique ID without having to check for collisions.

I currently do something like this, but the ID I currently generate is random and che

8条回答
  •  温柔的废话
    2021-02-04 18:09

    you can use a bitwise XOR to scramble some of the bits:

    select thefield ^ 377 from thetable;
    
    +-----+---------+
    | a   | a ^ 377 |
    +-----+---------+
    | 154 |     483 |
    | 152 |     481 |
    |  69 |     316 |
    |  35 |     346 |
    |  72 |     305 |
    | 139 |     498 |
    |  96 |     281 |
    |  31 |     358 |
    |  11 |     370 |
    | 127 |     262 |
    +-----+---------+
    

提交回复
热议问题