note 70404 deleted from function.rand by felipe
| From: | felipe@php.net | Date: | Sun, 30 Dec 2007 18:45:06 +0000 |
| Subject: | note 70404 deleted from function.rand by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134442@lists.php.net to get a copy of this message | ||
Note Submitter:
----
correction from the function below... this works better:
function randomselection($sql, $c) {
$data = getdata($sql);
$totalcount = count($data);
$j = array();
if($totalcount < $c) {//not enough data points
return $data;
}
for($i = 0; $i < $c; $i++) {
$j[$i] = mt_rand(0,$totalcount-1);
$newdata[$i] = $data[$j[$i]];
unset($data[$j[$i]]);
sort($data);
$totalcount--;
}
return $newdata;
}