Find a short URL algorithm that does not generate duplicate values

Source: Internet
Author: User
Tags repetition
Ask for a short URL algorithm that does not generate duplicate values, search the web for some, there is a certain probability of repetition, or can provide a repetition probability of the least algorithm is OK


Reply to discussion (solution)

This should be mister into a random string,
Then query whether the database already exists,
Does not exist on the storage,
There's another one to check,

The short address is only about five bits long,
I don't think it's possible to guarantee that no matter what algorithm is used,
So it can only be compared by the previous generation.

The simplest is that the random string is generated according to the corresponding ID, that is, looking like a random string, in fact, the ID is generated according to certain rules, basically do not get this ID range of the line, is not to use the duplicate

I think of myself is base62 algorithm hehe ~ ~ ~

 
 0); return $a;} Echo base62 (63);? >



Generates its base62 encoding by an integer ID
Like what
10
11
..
1a
1b
900000000 (900 million) = YUj72

Can be repeated in the database to record

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.