can anyone hep me me make a function that return random numbers but it will not generate another random number if he already pass the value for example it return 2, so after i call the function random again it will not return another 2 i want another numbers to be returned instead ?? can anyone help me here? function random($max){ srand ((double) microtime( )*1000000); $random_number = rand(0,$max); return $random_number; }
I couldn't reproduce that issue using that code (on PHP 5.2) mt_rand provides better random number by the way: function random($max){ return mt_rand(0,$max); } PHP: Up to you if you still want to use the wrapper, I don't bother with one.
Oh, I thought you meant the subsequent numbers were all the same instead of "they should never be the same". function random($max) { static $numbers = array(); do { $n = mt_rand(0, $max); } while (in_array($n, $numbers)); return $numbers[] = $n; } PHP: