oli22 Posted November 25, 2010 Share Posted November 25, 2010 I am using this code to play random videos from a folder, i have many videos but somehow the same ones are chosen too often, i don't know why... Would you know how to make it more random, so a wider variety of videos gets played??? Could it be because of the titles somehow( titles are not numbers-->titles are characters)? Would a random formula using mysql/tables be better? <?php function getRandomFile($path) { $files = array(); foreach( new DirectoryIterator($path) as $file ) { if($file->isFile()) { $files[] = $path . $file->getFilename(); } } $i = array_rand($files); return $files[$i]; } $path = "vids"; $url = 'http://127.0.0.1/randomPlay/'; $file = getRandomFile($path); //$final= str_replace('vids', $path, $file); //echo ($final) $final= substr($file, 4); //echo ($final); ?> Videos are in the "vids" folder Quote Link to comment https://forums.phpfreaks.com/topic/219840-not-random-enoughknow-how-to-improve-this-random-play-code/ Share on other sites More sharing options...
JasonLewis Posted November 27, 2010 Share Posted November 27, 2010 I don't believe in random. But... a suggestion is to create a session that stores selected videos. You could then come up with some kind of formula to determine when a video is chosen based on if it has already been shown or not. Quote Link to comment https://forums.phpfreaks.com/topic/219840-not-random-enoughknow-how-to-improve-this-random-play-code/#findComment-1140268 Share on other sites More sharing options...
Mchl Posted November 27, 2010 Share Posted November 27, 2010 First of all, how do you know some videos are chosen more often than others? Do you have something that counts that and analyzes the frequncies? Quote Link to comment https://forums.phpfreaks.com/topic/219840-not-random-enoughknow-how-to-improve-this-random-play-code/#findComment-1140303 Share on other sites More sharing options...
oli22 Posted November 28, 2010 Author Share Posted November 28, 2010 Hi,thanks I know some play more often because i refreshed the page many times to see the results and out of a bank of about 25 videos, the same 3 re-played over way too many times, bad random. a suggestion is to create a session that stores selected videos. You could then come up with some kind of formula to determine when a video is chosen based on if it has already been shown or not. I did have a thought about that but i am a real newbee so can someone tell me further how to do this? This random video thing happens automaticaly when people arrive on the web page. There is no login... Quote Link to comment https://forums.phpfreaks.com/topic/219840-not-random-enoughknow-how-to-improve-this-random-play-code/#findComment-1140641 Share on other sites More sharing options...
Mchl Posted December 1, 2010 Share Posted December 1, 2010 Hi,thanks I know some play more often because i refreshed the page many times to see the results and out of a bank of about 25 videos, the same 3 re-played over way too many times, bad random. Sorry,but until you actually have measured that over several hundreds page loads, I'll remain unconvinced. Quote Link to comment https://forums.phpfreaks.com/topic/219840-not-random-enoughknow-how-to-improve-this-random-play-code/#findComment-1141733 Share on other sites More sharing options...
chmpdog Posted December 8, 2010 Share Posted December 8, 2010 there is a correlation: http://www.random.org/analysis/#visual Quote Link to comment https://forums.phpfreaks.com/topic/219840-not-random-enoughknow-how-to-improve-this-random-play-code/#findComment-1144253 Share on other sites More sharing options...
oli22 Posted December 9, 2010 Author Share Posted December 9, 2010 Chmpdog, that random info is a great demonstration.I wonder if they have a code i can use, i will browse them. Otherwise i guess i will try to make a php code to memorize and create a filter to even out most played, work in progress... Quote Link to comment https://forums.phpfreaks.com/topic/219840-not-random-enoughknow-how-to-improve-this-random-play-code/#findComment-1144987 Share on other sites More sharing options...
doni49 Posted February 6, 2011 Share Posted February 6, 2011 Chmpdog, that random info is a great demonstration.I wonder if they have a code i can use, i will browse them. Otherwise i guess i will try to make a php code to memorize and create a filter to even out most played, work in progress... From what I can tell, the random.org site is using the Mersenne Twister method of getting a random number. PHP has a Mersenne Twister random function called mt_rand and you can find info on that function at php.net/mt_rand. Quote Link to comment https://forums.phpfreaks.com/topic/219840-not-random-enoughknow-how-to-improve-this-random-play-code/#findComment-1170526 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.