I can’t stress how important it is to seed your randomisation process in code! better still something we found in the BBS Days was if we didn’t seed from a token from outside our systems abstraction layer we would go in circles and so would our users. Here at chronolabs we offer a feed of randomly changing token on each impression, it also randomly displays a different number of them this is from http://seed.feeds.labs.coop in the example below I use DOM to load the XML, Extract the randomisation tokens and then with mt_srand and srand seed the random selecting processes! The following function when you call it will seed your random selection process in both the old and new random selection routines all you need to do is call the function! This will work with any version of PHP 5 and any earlier with DOM Objectivity.
function makeRandomSeeded() {
$file = 'http://seed.feeds.labs.coop/';
$doc = new DOMDocument();
$doc->loadHTMLFile($file);
$skip = array('This feed can', 'Current mode is');
$elements = $doc->getElementsByTagName('description');
foreach($elements as $element) {
$seed = $element->nodeValue;
$found = false;
foreach($skip as $find) {
if (substr($seed, 0, strlen($find))==$find) {
$found = true;
}
}
if ($found==false)
$seeds[] = $seed;
}
shuffle($seeds);
mt_srand($seeds[mt_rand(0, count($seeds)-1)]);
srand($seeds[mt_rand(0, count($seeds)-1)]);
}
Remember when PHP says an integer this also include any character of the Ascii chart if you would like to see an example of this do the following:
<?php
$a = "000A";
while($a!="001B") {
echo $a;
$a++;
}
?>