
Originally Posted by
ozonew4m
hello guys and gals
lets say i have 100 values in the array..
what i want to do is provide a key to randomly generate an array of 50 values from the 100
the key needs to generate exactly the same values every time from the array (so i guess its not really random)
so if i give the key value of say 12345
it will generate the same 50 from the 100 every time..
i thought about using md5 in combination with shuffle but im not sure how to do it completely
any guidance please
For example:
PHP Code:
function random_subarray($ary, $len, $key) {
srand($key);
shuffle($ary);
return array_slice($ary, 0, $len);
}
# example
$chars = range('a', 'z');
print_r(random_subarray($chars, 5, 123));
same $key value generates same selection every time.
hope this helps.
Bookmarks