dreamwest Posted October 9, 2009 Share Posted October 9, 2009 How does youtube generate their video ids?? Most of them are only 5-12 chars long and they have over 180 Million videos watch?v=ewfFcmdSdck Link to comment https://forums.phpfreaks.com/topic/177035-how-does-youtube-do-it/ Share on other sites More sharing options...
jcombs_31 Posted October 9, 2009 Share Posted October 9, 2009 The lottery is only 6 numbers, any idea on the combination of those numbers. Link to comment https://forums.phpfreaks.com/topic/177035-how-does-youtube-do-it/#findComment-933436 Share on other sites More sharing options...
PugJr Posted October 9, 2009 Share Posted October 9, 2009 The lottery is only 6 numbers, any idea on the combination of those numbers. It depends which country. Lotteries where I'm from are 6 number sets, with the potential of each one having up to 2 numbers in each set. And those numbers are supposed to be randomly generated. (Conspiracy people such as myself believe otherwise...) Link to comment https://forums.phpfreaks.com/topic/177035-how-does-youtube-do-it/#findComment-933437 Share on other sites More sharing options...
cags Posted October 9, 2009 Share Posted October 9, 2009 The Lottery here (UK) is 6 numbers and I believe the approximate chances of winning are around 14 and 1/2 million to 1. Link to comment https://forums.phpfreaks.com/topic/177035-how-does-youtube-do-it/#findComment-933440 Share on other sites More sharing options...
PugJr Posted October 9, 2009 Share Posted October 9, 2009 Oh wait, I think I'm not thinking right. I think the lottery is the same, I just was thinking that '##' are two numbers, when that really is just 1 number. So nevermind. Don't know what I was thinking. Link to comment https://forums.phpfreaks.com/topic/177035-how-does-youtube-do-it/#findComment-933442 Share on other sites More sharing options...
corbin Posted October 9, 2009 Share Posted October 9, 2009 watch?v=ewfFcmdSdck The codes are case sensitive and appear to be 11 characters that can be a-zA-Z0-9_-. So, 26*2 + 10 + 2 = 64 64^11 options: 73786976294838206464 That's how they do it . Link to comment https://forums.phpfreaks.com/topic/177035-how-does-youtube-do-it/#findComment-933511 Share on other sites More sharing options...
PugJr Posted October 9, 2009 Share Posted October 9, 2009 watch?v=ewfFcmdSdck The codes are case sensitive and appear to be 11 characters that can be a-zA-Z0-9_-. So, 26*2 + 10 + 2 = 64 64^11 options: 73786976294838206464 That's how they do it . He isn't saying if its possible to have 180 million different combination within 12 or 11 characters. He is saying how do they generate the id. Whats the formula. Link to comment https://forums.phpfreaks.com/topic/177035-how-does-youtube-do-it/#findComment-933518 Share on other sites More sharing options...
corbin Posted October 9, 2009 Share Posted October 9, 2009 Ahhhh.... I read the generate part then entirely forgot about it when I read the 180 million part . Link to comment https://forums.phpfreaks.com/topic/177035-how-does-youtube-do-it/#findComment-933523 Share on other sites More sharing options...
PugJr Posted October 9, 2009 Share Posted October 9, 2009 Ahhhh.... I read the generate part then entirely forgot about it when I read the 180 million part . But regarding to what he wants, what do you think it could be? I find it hard to be the name of the youtube video. Possibly they are just number ids, except being just numbers, they are turned into letters/numbers. Is it possible for youtube videos ID to change after its been uploaded? Also, dreamwest, could you get me two video ids that were uploaded right after another? Link to comment https://forums.phpfreaks.com/topic/177035-how-does-youtube-do-it/#findComment-933525 Share on other sites More sharing options...
smerny Posted October 9, 2009 Share Posted October 9, 2009 probably some type of hash i guess... changing video ID... probably not, although they could assign different names to those ID's probably "could you get me two video ids that were uploaded right after another?" being that there are thousands of people probably uploading videos at a time... thats probably not possible Link to comment https://forums.phpfreaks.com/topic/177035-how-does-youtube-do-it/#findComment-933527 Share on other sites More sharing options...
PugJr Posted October 9, 2009 Share Posted October 9, 2009 probably some type of hash i guess... There is one problem with hashes though. Uh, well I forgot the term, but its when there are two somethings with the same hash. I suppose the odds wouldn't be great to any degree. As corb calculated it to 73786976294838206464 different hashes which would bring the chances to near 0. So I suppose they hashed it. being that there are thousands of people probably uploading videos at a time... thats probably not possible Eh, thats true. Link to comment https://forums.phpfreaks.com/topic/177035-how-does-youtube-do-it/#findComment-933529 Share on other sites More sharing options...
corbin Posted October 9, 2009 Share Posted October 9, 2009 probably some type of hash i guess... There is one problem with hashes though. Uh, well I forgot the term, but its when there are two somethings with the same hash. I suppose the odds wouldn't be great to any degree. As corb calculated it to 73786976294838206464 different hashes which would bring the chances to near 0. So I suppose they hashed it. Hash collision? When generating unique identities, avoiding collisions is fairly easy: do { code = generate code; } while(code exists); (There are of course locking problems since theoretically in the time that code was said to not exist and actually inserted the same code could have been generated.) As far as collisions go, imagine how unlikely a collision would be on this: md5(video name . microtime(true)); (Of course they're not using md5 since the format doesn't match it, but you get the point.) Link to comment https://forums.phpfreaks.com/topic/177035-how-does-youtube-do-it/#findComment-933533 Share on other sites More sharing options...
dreamwest Posted October 9, 2009 Author Share Posted October 9, 2009 I cooked up this: function video_gen($min=6,$max=6,$id){ /*has a default min value of 6 and maximum value of 6*/ $vid=""; // to store generated password for($i=0;$i<rand($min,$max);$i++){ $num=rand(48,122); if(($num >= 97 && $num <= 122)) $vid.=chr($num); else if(($num >= 65 && $num <= 90)) $vid.=chr($num); else if(($num >=48 && $num <= 57)) $vid.=chr($num); else $i--; } return $vid; } $vid = video_gen(6,6, 87458 ); $result = mysql_query("SELECT id FROM videos WHERE vid='{$vid}' "); if($result){ $video_num = mysql_num_rows( $result ); if ($video_num == 0) { mysql_query("insert into videos set vid ='{$vid}' "); } } Outputs somthing like "WcAEwG" Thus resulting in unique ids for every video......HOWEVER i think it would be a problem checking 180million + rows. Link to comment https://forums.phpfreaks.com/topic/177035-how-does-youtube-do-it/#findComment-933568 Share on other sites More sharing options...
xsist10 Posted October 9, 2009 Share Posted October 9, 2009 Try this [from www.php.net/uniqid] $key = md5(uniqid(mt_rand(), true)); Link to comment https://forums.phpfreaks.com/topic/177035-how-does-youtube-do-it/#findComment-933569 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.