note 73360 deleted from function.rand by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
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>';

?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.