note 73360 deleted from function.rand by felipe

From: Date: Sun, 30 Dec 2007 18:45:22 +0000
Subject: note 73360 deleted from function.rand by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-134447@lists.php.net to get a copy of this message
Note Submitter: ---- Everyone wants to use so much code to get multiple unique AND at the same time have them also be random values. Here's the smallest code I could think of to do it - no loops necessary: <?php // demonstrates how to get any // number of unique random numbers // make an array with values 1 through 100 $a=range(1,100); // randomly order it shuffle($a); // pull out the first two values, for example // they will be random AND non-overlapping $rand1=$a[0]; $rand2=$a[1]; echo '<pre>'; print_r($rand1); echo '<br>'; print_r($rand2); echo '</pre>'; ?>

« previous php.notes (#134447) next »