note 73360 added to function.rand

From: Date: Mon, 19 Feb 2007 18:59:54 +0000
Subject: note 73360 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-123585@lists.php.net to get a copy of this message
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>'; ?> ---- Server IP: 69.147.83.197 Probable Submitter: 71.167.160.198 ---- Manual Page -- http://www.php.net/manual/en/function.rand.php Edit -- https://master.php.net/note/edit/73360 Del: integrated -- https://master.php.net/note/delete/73360/integrated Del: useless -- https://master.php.net/note/delete/73360/useless Del: bad code -- https://master.php.net/note/delete/73360/bad+code Del: spam -- https://master.php.net/note/delete/73360/spam Del: non-english -- https://master.php.net/note/delete/73360/non-english Del: in docs -- https://master.php.net/note/delete/73360/in+docs Del: other reasons-- https://master.php.net/note/delete/73360 Reject -- https://master.php.net/note/reject/73360 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123585) next »