Welcome to my site... Have a nice day...

Sunday, 16 February 2014

[PHP] How generate unique randoms



Hi my friends.

Today i will show u how generate unique random integer on php...

This is oru function to suffle our numbers.. For randomize :)
function UniqueRandom($min$max$leng) {
    
$numbersrange($min$max);
    
shuffle($numbers);
    return 
array_slice($numbers0$leng);
}  
How it use:
<?php
print_rUniqueRandom(0,25,5) );
?>

OutPut:
 Array
(
    [0] => 12
    [1] => 19
    [2] => 5
    [3] => 22
    [4] => 3
) 


And you can use that code like that:
<?php
$numbers=UniqueRandom(0,25,5);
echo numbers[0];
echo $numbers[3];
?>

0 comments: