I have a PHP script that needs to randomize an array with consistent results so that it can present the first few elements to the user, and then they can extract more results from the same shuffled set if they want.
I am currently using this (based on the Fisher Yates algorithm, which I consider):
function shuffle(&$array, $seed) { mt_srand($seed); for ($a=count($array)-1; $a>0; $a--) { $b = mt_rand(0, $a); $temp = $array[$a]; $array[$a] = $array[$b]; $array[$b] = $temp; } }
Which works well on my local installation, but Suhosin was installed on the server it should be running on, which overrides mt_srand, which means that the seed is ignored, the array is just randomly shuffled, and the user gets duplicate results.
Everything I found on Google suggests that I need to disable suhosin.mt_srand.ignore (and suhosin.srand.ignore, not sure if the latter is relevant), so I put the following in .htaccess:
php_flag suhosin.mt_srand.ignore Off php_flag suhosin.srand.ignore Off
I do not have access to php.ini on this server, so AFAIK is the only way to do this. The problem is that it has no effect - phpinfo () still shows both settings as On, while I can change other Suhosin settings using .htaccess without any problems.
So, I believe that what I'm looking for is either a way to disable suhosin.mt_srand.ignore (or the reason it doesn't work), or a workaround for generating a random number generator from PHP. Or do I just need to implement another RNG?
Any help would be greatly appreciated. Thanks!