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
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.
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.
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.
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.
in distributed environment it is simpler to generate random numbers for identifiers than sequential numbers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With