tomdelonge Posted January 30, 2009 Share Posted January 30, 2009 Alright, it's statistically random, but I want to order some rows in mysql, and then have every single one be possible, but the ones near the top be more likely to be chosen. Understand? I don't... That's why I'm asking, how should I do that? Quote Link to comment https://forums.phpfreaks.com/topic/143196-weighted-random-number/ Share on other sites More sharing options...
genericnumber1 Posted January 31, 2009 Share Posted January 31, 2009 Look into poisson distribution algorithms. Quote Link to comment https://forums.phpfreaks.com/topic/143196-weighted-random-number/#findComment-751032 Share on other sites More sharing options...
sasa Posted January 31, 2009 Share Posted January 31, 2009 try <?php $array_of_pos = array(1,2,3,4,5); for ($i=0;$i<10000;$i++){ foreach ($array_of_pos as $pos) //create new value foreach positions $tmp[$pos] = ($pos + 7) * rand(); asort($tmp);//sort new array $tmp = array_flip($tmp); $first = array_shift($tmp);//get 1st element $out[]=$first; // put element for analise } $distribution = array_count_values($out); ksort($distribution); print_r($distribution); ?>[7php] Quote Link to comment https://forums.phpfreaks.com/topic/143196-weighted-random-number/#findComment-751215 Share on other sites More sharing options...
redarrow Posted January 31, 2009 Share Posted January 31, 2009 brilliant bit off coding nice one. sorry but all them functions in one is grate was wondering how it all worked in a real worlds situation. love the example. Quote Link to comment https://forums.phpfreaks.com/topic/143196-weighted-random-number/#findComment-751222 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.