php: number only hash?

后端 未结 7 1994
眼角桃花
眼角桃花 2020-12-03 01:00

In php is there a way to give a unique hash from a string, but that the hash was made up from numbers only?

example:

return md5(234); // returns 098f         


        
7条回答
  •  感情败类
    2020-12-03 01:14

    Just use my manual hash method below:

    Divide the number (e.g. 6 digit) by prime values, 3,5,7.

    And get the first 6 values that are in the decimal places as the ID to be used. Do a check on uniqueness before actual creation of the ID, if a collision exists, increase the last digit by +1 until a non collision.
    E.g. 123456 gives you 771428 123457 gives you 780952 123458 gives you 790476.

提交回复
热议问题