title: Randomize a PHP array with a seed?
body: <p>I'm looking for a function that I can pass an array and a seed to in PHP and get back a "randomized" array. If I passed the same array and same seed again, I would get the same output.</p>
  
  <p>I've tried this code</p>
  
  <pre>
  //sample array
  $test = array(1,2,3,4,5,6);
  //show the array
  print_r($test);
  
  //seed the random number generator
  mt_srand('123');
  //generate a random number based on that
  echo mt_rand();
  echo "\n";
  
  //shuffle the array
  shuffle($test);
  
  //show the results
  print_r($test);
  
  </pre>
  
  <p>But it does not seem to work. Any thoughts on the best way to do this?</p>
  
  <p>This question dances around the issue but it's old and nobody has provided an actual answer on how to do it: <a href="https://stackoverflow.com/questions/3169805/">Can i randomize an array by providing a seed and get the same order?</a> - "Yes" - but how?</p>
  
  <h3>Update</h3>
  
  <p>The answers so far work with PHP 5.1 and 5.3, but not 5.2. Just so happens the machine I want to run this on is using 5.2.</p>
  
  <p>Can anyone give an example without using mt_rand? It is "broken" in php 5.2 because it will not give the same sequence of random numbers based off the same seed. See the <a href="http://php.net/manual/en/function.mt-rand.php" rel="noreferrer">php mt_rand page</a> and the <a href="https://bugs.php.net/bug.php?id=40724" rel="noreferrer">bug tracker</a> to learn about this issue.</p>