note 93364 deleted from function.array-pop by danbrown
| From: | danbrown@php.net | Date: | Sat, 05 Sep 2009 19:37:17 +0000 |
| Subject: | note 93364 deleted from function.array-pop by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-160246@lists.php.net to get a copy of this message | ||
Note Submitter: jim203nospamplz at plznospamaol dot com
----
Pseudorandom array sort, based on salt input, with the same output every time.
<?php
// sort array based on $SALT;
$SALT = 'a4f1'; // pick any hex
$temparray = $arrayToSort;
$arrayToSort = array();
$startingFileNumber = hexdec($SALT) % count($temparray);
$fileNumber = $startingFileNumber;
$filesDone = 0;
while ($filesDone < count($temparray))
{
// cycle round the array on a number that is not a factor of the count until got all
$theJumpNumber = round(count($temparray)/2) + $startingFileNumber; // use of startingfilenumber
randomizes the jump number
while (count($temparray) % $theJumpNumber == 0)
$theJumpNumber--;
$filesDone++;
$fileNumber = ($fileNumber+$theJumpNumber) % count($temparray);
array_push($arrayToSort,$temparray[$fileNumber]);
}
unset($temparray);
?>
More info at http://www.zyngal.com/blog/