# Implementation of the short URL Principle 1

Source: Internet
Author: User

Today, I almost always had this problem after going home, because of a detour. The short URL is composed of any 6 of the 62 characters in the a-zA-Z0-9, and the total number after the combination is
More than 50 billion. I had been trying to use the hexadecimal bitwise operation to accumulate the carry, but it was always unsuccessful. Later I read it online and said that I performed the MD5 operation on the original URL, four combinations can be obtained at will.
A method, but the results will be repeated. Although the probability is small, this method is also passed. Finally, after thinking about it for more than half a night, a method will never be repeated.Algorithm.

First of all, I'm sure that these 62 characters are randomly composed of six of them, and the number of combinations is as high as more than 50 billion. If we map the combination of numbers and characters, can we only get the unique string,
For example, 62nd combinations are aaaaa9 and 63rd combinations are aaaaba. Then, the shuffling algorithm is used to disrupt the original string and save it. Then, the character strings at the corresponding position are unordered.

A simple example

Only characters A, B, C, and D are provided. After shuffling, the characters B, A, D, and C are used as strings. The number of characters in a string is 64.

When performing URL conversion, First insert the original URL to the database, and then insert the returned id based on the database to find the corresponding string. For example, if the returned ID is 1, the string combination above is

Bbb

Similarly, when ID is 2, the string combination is

BBA

And so on

3 -- BBD

4 -- BBC

5 -- bab

6 -- Baa

8 -- bac

......

It is not possible to duplicate the string until the 64-character combination is reached. Therefore, if the preceding 62 characters are used and any six characters are used to combine them into strings, repeat may occur only when your data inventory reaches more than 50 billion.

Form: http://www.uchome8.com/209

The above is the idea of others. It is a good idea. Save it. But if you need to set up a Personal Short website, how can we achieve it.

If the length of a non-personalized short domain name is set to 6, the length of a personal short domain name cannot be 6, and can be stored in different tables for any other number of personal short domain names and non-personalized domain names, it seems that the problem is solved. Consider it again.

Personal Short domain names are mainly used to help you remember connections that are not easy to remember. For example, most people cannot remember Microsoft's web site (I haven't remembered it now). After using personal domain names to save the Web site, set personality to XX. CN/weiruan. It will be very convenient to visit later. I don't know if anyone is using this function. Maybe it's just my personal thoughts.

Related Keywords:

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.