Given sample URL: http://www.youtube.com/watch?v=xqvObyU2ITs, any availabale algorithm to generate youtube style video id (xqvObyU2ITs)? Thanks!<p>-Jack
Here's a very quick and dirty one for Ruby:<p>require 'zlib'<p>base = "whatever"<p>salt = "whatever"<p>Zlib.crc32(base + salt).to_s(36)<p>This will generate 6-7 character strings. Not sure how likely collisions are, but they should be rare enough that a simple check/regenerate should work.
First thought is that they're generating a globally unique video ID number and base-62 encoding it to keep the URL shorter. Maybe not though?<p>You could do that easily by just base-62 encoding your table's auto-generated primary key.
Or, using C with /dev/urandom: <a href="http://alan.dipert.org/post/84526522/random-strings-with-c" rel="nofollow">http://alan.dipert.org/post/84526522/random-strings-with-c</a>
uh, in python:<p><pre><code> import string, random
''.join(random.sample((string.letters+string.digits), 12))
</code></pre>
I hope that's what you were asking for. If not, you might want to clarify your question.