I found this in an old thread: $arr = array(); while ( count($arr) < 10 ) { $x = mt_rand(1,10); if ( !in_array($x,$arr) ) { $arr[] = $x; echo "$x<br>"; } } PHP: And it does exactly what I am looking for, except for I'm trying to make a change. I would like to be able to use the random numbers anywhere in the script using an array. The numbers would be generated and put in to an array on page load, and I could call them throughout the page using something like $randomN[2]. So $randomN[2] woudl call the 2nd (well, actually the third) number in the array. This would make $randomN[0] through $randomN[9] all unique. Can anyone help me with this? I'm struggling.
You're most of the way there already... just had to change the array name and remove the echo. $randomN = array(); while ( count($randomN) < 10 ) { $x = mt_rand(1,10); if ( !in_array($x,$randomN) ) { $randomN[] = $x; } } PHP:
Ahh.. I'll give this a go in a minute. Thanks Hoff - You sexy bunch of Trans-Am driving, swim short wearing love