>>>>> "a" == andrew <[EMAIL PROTECTED]> writes:
> Hi, is there a quick way to create an array of integers, randomized
> and without repeats?
> e.g. if my set is 1 - 10, create an array whoese key values are 1
> through 10, with corresponding key values as a random set of the
> same 1 through 10??
> thanks in advance for any suggestions :) andrew
Yeah, this will give you an array of the numbers 1 - 10 in random
order. If you want a different range, change the parameters to suit.
<?php
function rand_array( $start, $finish ) {
srand ( (double) microtime() * 1000000);
$rand_array = range( $start, $finish );
// it really irritates me the way PHP's sort functions mess around
// with the original array rather than returning a sorted array so
// I can assign it to where I want it.
shuffle( $rand_array );
return $rand_array;
}
print_r( rand_array(1, 10) );
?>
--
Robin Vickery.................................................
BlueCarrots, 14th Floor, 20 Eastbourne Terrace, London, W2 6LE
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]