0
//this function generates the distinct random numbers for the 25 requirment
function unique_rand_numbers($numbers)
{
 for($i = 1; $i = 40; $i++)
 {
	$numbers = $i;
 }
 $array = array();
 
 //get unique random keys from $numbers array.
 $rand_keys = array_rand($numbers,25);
 
 //this sorts the distinct random numbers taken from $numbers in random order.
 sort($rand_keys);

 //stuck on this part..i need to store more than one value here
//theres 25 intergers in $rand_numbers..i'd a ppricaite any help.

 $array[][] = $rand_numbers;
 
 return $rand_numbers;
 }

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by diafol
0
<?php
function unique_rand_numbers($min=1,$max=40,$inc=1,$num=25){
 $rand_keys = array_rand(range($min,$max,$inc),$num);
 sort($rand_keys);
 return $rand_keys;
}

print_r(unique_rand_numbers());
echo "<br /><br /><br />";
print_r(unique_rand_numbers(1,50,1,6));
?>

If you need a list of numbers in an array, range() can save some time. I've included optional parameters in the function, but you can take these out and hardcode your values if you want.

Edited by diafol: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.