note 49792 added to function.rand

From: Date: Tue, 08 Feb 2005 20:50:49 +0000
Subject: note 49792 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-84685@lists.php.net to get a copy of this message
If you want to generate two +different+ random numbers in the same range: <? function fn_arrRandom($min, $max){ // generate two random numbers $iRandom1 = rand($min, $max); $iRandom2 = rand($min, $max); // compare them if ($iRandom1 !== $iRandom2){ // the numbers are different, great } else { // the numbers are equal, try again return fn_arrRandom($min, $max); } return array($iRandom1, $iRandom2); } print_r(fn_arrRandom(3, 13)); ?> The above will output two different random numbers in an array: Array ( [0] => 5 [1] => 7 ) ---- Manual Page -- http://www.php.net/manual/en/function.rand.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49792 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49792&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49792&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49792&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49792&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49792&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49792&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#84685) next »