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