note 83365 added to function.mt-rand

From: Date: Thu, 22 May 2008 14:24:44 +0000
Subject: note 83365 added to function.mt-rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-139614@lists.php.net to get a copy of this message
I think this will work faster. <?php function unique_random($Min,$Max,$num){ //this will swap min an max values if $Min>$Max if ($Min>$Max) { $min=$Max; $max=$Min; } else { $min=$Min; $max=$Max; } //this will avoid to enter a number of results greater than possible results if ($num>($max-$min)) $num=($max-$min); $values=array(); $result=array(); for ($i=$min;$i<=$max;$i++) { $values[]=$i; } for ($j=0;$j<$num;$j++){ $key=mt_rand(0,count($values)-1); $result[]=$values[$key]; unset($values[$key]); sort($values); } return $result; } ?> ---- Server IP: 213.92.11.19 Probable Submitter: 89.97.102.219 ---- Manual Page -- http://www.php.net/manual/en/function.mt-rand.php Edit -- https://master.php.net/note/edit/83365 Del: integrated -- https://master.php.net/note/delete/83365/integrated Del: useless -- https://master.php.net/note/delete/83365/useless Del: bad code -- https://master.php.net/note/delete/83365/bad+code Del: spam -- https://master.php.net/note/delete/83365/spam Del: non-english -- https://master.php.net/note/delete/83365/non-english Del: in docs -- https://master.php.net/note/delete/83365/in+docs Del: other reasons-- https://master.php.net/note/delete/83365 Reject -- https://master.php.net/note/reject/83365 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139614) next »