Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do websites generate random alphanumeric strings for urls instead of using row ids?

Why does many sites (youtube is good example) generate string of random number and letter instead of using for example the row id?

usually its something likes this

bla?v=wli4l73Chc0

instead of like

bla?id=83934

Is it just to keep it short if you have many rows? Or is there other good things about this? Because i can imagine: bla?id=23934234234 dont look so nice

Thanks and cheers

like image 464
jorm Avatar asked Apr 05 '10 22:04

jorm


People also ask

Why do URLs have random letters and numbers?

These identifiers are long random strings of letters and numbers in order to make sure that there are no duplicates. For example, every video n YouTube has a random identifier to distinguish it from all the other videos, and if you copy a link to the video it will contain this identifier.

What is a random URL?

This Random URL concept is used to make sure that the URLs are kept really very short, somewhat only 7 - 10 characters, but if we keep 7 to 10 characters then there is a chance of a repetition and the URL might be duplicate of other URL, making is harder to guess which longer URL is associated with this short URL.

How do you generate random unique alphanumeric strings in C#?

Initialize an empty string and name it as “ran”. Choose the size of the string to be generated. Now using Next() method generate a random number and select the character at that index in the alphabet string. Append that character to randomString.


2 Answers

They are actually not random strings. Normally they are numbers (usually row IDs) that are encoded in Base-36 encoding (obviously not always the case, but there are many that use it).

Why do they use it? Because a Base-36 encoded number string is shorter than the original.

For example: 1234567890 in Base-36 is kf12oi, almost 50% shorter.

See this Wikipedia article. Check the "Uses in practice" section to see who is using it.

like image 106
Strelok Avatar answered Oct 23 '22 05:10

Strelok


in distributed environment it is simpler to generate random numbers for identifiers than sequential numbers.

like image 23
Yaroslav Avatar answered Oct 23 '22 05:10

Yaroslav