/ Published in: PHP
Repeatable Fisher Yates Array Shuffle based on given random string. If no seed is provided the current second will be used (not to use as a pure random shuffle... based on microseconds)
Expand |
Embed | Plain Text
function fyshuffle(&$items,$seedstring) { if (!$seedstring) { } else { $seedval = $seedstring; } else { } } $tmp = $items[$i]; $items[$i] = $items[$j]; $items[$j] = $tmp; } }
Comments
Subscribe to comments
You need to login to post a comment.

To understand how this is valuable you need to know how it works. Its a seeded, or what I call a "static" shuffle. Meaning that it will shuffle to the exact same results if the same seed is given. This is tremendous for doing large SEO projects. If you have an array of hundreds of possible title tags that could pertain to the group of articles, then just use the fyshuffle, using the url as the seed, to shuffle your array of possible titles. Then pick the first title. This way the search engines will always get the same title as they did last time, but it won't be the same as the next article in the group.
Another good use is random name generators, since the same result will be given every time for each name. Sample script :