Creating your own Tinyurl style uid

前端 未结 8 1701
抹茶落季
抹茶落季 2020-12-02 11:30

I\'m writing a small article on humanly readable alternatives to Guids/UIDs, for example those used on TinyURL for the url hashes (which are often printed in magazines, so n

相关标签:
8条回答
  • 2020-12-02 12:23

    Why do you want to use a random function? I always assumed that tinyurl used a base 62 (0-9A-Za-z) representation of a sequential Id. No clashes and the urls are always as short as possible.

    You would have a DB table like

    Id  URL
     1  http://google.com
     2  ...
    ... ...
    156 ...
    ... ...
    

    and the corresponding URLs would be:

    http://example.com/1
    http://example.com/2
    ...
    http://example.com/2W
    ...
    
    0 讨论(0)
  • 2020-12-02 12:29

    I would generate a random value representative of the data that you are going to hash, and then hash that and check clahses rather than trying to simulate with random manually made hashes. This will give you a better indicator. And you will have more randomness because you will have more to randomize (Assuming your data to be hashed is larger :) ).

    0 讨论(0)
提交回复
热议问题