note 73710 added to function.rand

From: Date: Wed, 07 Mar 2007 15:00:40 +0000
Subject: note 73710 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-124195@lists.php.net to get a copy of this message
kurtubba's code was helpful, but didn't quite work for me. Here's my version in case anyone has the same issue: <?php function UniqueRands($min, $max, $keys){ static $retval = array(); $x = rand($min,$max); if(!in_array($x,$retval)){ array_push($retval, $x); } if($keys > count($retval)){ UniqueRands($min, $max, $keys); } return $retval; } $var = UniqueRands(1, 4, 4); print_r($var); ?> Bear in mind I'm not the best with php! But my version worked for me at least. ---- Server IP: 194.145.210.4 Probable Submitter: 212.219.105.21 (proxied: 192.168.2.14) ---- Manual Page -- http://www.php.net/manual/en/function.rand.php Edit -- https://master.php.net/note/edit/73710 Del: integrated -- https://master.php.net/note/delete/73710/integrated Del: useless -- https://master.php.net/note/delete/73710/useless Del: bad code -- https://master.php.net/note/delete/73710/bad+code Del: spam -- https://master.php.net/note/delete/73710/spam Del: non-english -- https://master.php.net/note/delete/73710/non-english Del: in docs -- https://master.php.net/note/delete/73710/in+docs Del: other reasons-- https://master.php.net/note/delete/73710 Reject -- https://master.php.net/note/reject/73710 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#124195) next »