YouTube URL algorithm?

后端 未结 11 1890
遇见更好的自我
遇见更好的自我 2020-12-04 09:39

How would you go about generating the unique video URL\'s that YouTube uses?

Example:

  • http://www.youtube.com/watch?v=CvUN8qg9lsk
11条回答
  •  孤街浪徒
    2020-12-04 10:17

    There is no need to use a hash. It is probably just a quasi-random 64 bit value passed through base64 or some equivalent.

    By quasi-random, I mean it is just a one-to-one mapping with the counting integers, just shuffled.

    For example, you could take a monotonically increasing database id and multiply it by some prime near 2^64, then base64 the result. If you did not want people to be able to guess, you might choose a more complex mapping or just pick a random number that is not in the database yet.

    Normal base64 would add an equals at the end, but in this case it is implied because the size is known. The character mapping could easily be something besides the standard.

提交回复
热议问题