数据库 - 求比较方便的基于自增id映射出一串唯一数字id的算法
迷茫
迷茫 2017-04-22 08:59:53
0
2
815

rails默认用自增id作为pk,并且url上通过id找到相应的资源,不过我想像微博那样通过一串长数字去定位资源
如:

http://weibo.com/u/1857759250

这种形式的数字id。

该数字串最好能够有跟自增id的一定的对应关系,比如说是自增id经过一定的算法生成。
该数字串必须是唯一的,最好是不连续的,最好在10位以内。

谢谢

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
阿神

A relatively simple method is to find a large number and xor it. The algorithm is simple and the number of digits is easy to control

You can make a slight deformation to remove the regularity. For example, to find 16 large numbers, take the last 4 digits of the original number to find the corresponding large number, then the last 4 digits remain unchanged, and the other digits are xored with the large number. The last 4 digits are also included The pattern can be 1st, 3rd, 6th, 15th and so on

刘奇

id + fixed value, md5, isn’t it possible?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template