How does such a short URL is how to do the hair number

Source: Internet
Author: User
Testing in this http://nh.gs/

I generate URLs consecutively to get
Http://nh.gs/4hm
Http://nh.gs/con

After base62
4HM = 16452
con = 47639

The traditional is to generate 5 to 6 bits, this should be self-increasing, but why the continuous generation of the base62 after the value is so much worse, supposedly continuous, I think it should be used some way to prevent the recurrence of duplication, this is the short URL source of the download address Http://pan.baidu.com/s/1pJ4zLDD

I analyzed the source code but could not find the core of the build, Baidu Google also looked for, so to ask the great God to help (⊙0⊙)

Reply content:

Testing in this http://nh.gs/

I generate URLs consecutively to get
Http://nh.gs/4hm
Http://nh.gs/con

After base62
4HM = 16452
con = 47639

The traditional is to generate 5 to 6 bits, this should be self-increasing, but why the continuous generation of the base62 after the value is so much worse, supposedly continuous, I think it should be used some way to prevent the recurrence of duplication, this is the short URL source of the download address Http://pan.baidu.com/s/1pJ4zLDD

I analyzed the source code but could not find the core of the build, Baidu Google also looked for, so to ask the great God to help (⊙0⊙)

Uploads/Web/Lib/Action/IndexAction.class.phpLine No. 268.

            $data['tinyurl'] = getfreetiny($model->field('tinyurl')->select());

getfreetinyDefined in the Uploads/Web/Common/common.php 33rd row.
getfreetinyThe function calls it above (line 22nd) get_tinyurl to convert to the getfreetiny corresponding string according to the random number generated in the.

So the conclusion is that the number is randomly generated. That's why you can see the difference between the results.

Probably looked at the source code, found a few sentences in the ApiAction.class.php

php    public function thirdapi()    {        $method = trim($_GET['api']);        $url = trim($_POST['url']);        $url = empty($url) ? 'http://www.baidu.com': $url;        if($method=='dwz')        {            $baseurl  = "http://dwz.cn/create.php";            $data=array('url'=>$url);        }

So it is estimated that the dwz.cn API is called to generate the algorithm that is not implemented by itself.

Re-duplicate Bibai

First, the probability of repeating is very small.

And then you can regenerate it even if it's a duplicate.

Just the sauce purple.

do {    生成隨機數} while (重複)
  • Related Article

    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.