note 114019 added to function.mt-srand

From: Date: Wed, 01 Jan 2014 16:38:00 +0000
Subject: note 114019 added to function.mt-srand
Groups: php.notes 
Request: Send a blank email to php-notes+get-198064@lists.php.net to get a copy of this message
This is the full extended version of makeRandomSeeded() that we have defined any further updates will be on http://ceo.blogs.labs.coop as an article <?php /** * Function: makeRandomSeeded() - Seeds the Selection Process of Random Sorting & Selection * * @param $filename string - Source of Seeding XML * @return integer - the seed used */ function makeRandomSeeded($filename = 'http://seed.feeds.labs.coop/') { error_reporting(E_ERROR); // Loads XML by forcing loadXML with DOM $xml = file_get_contents($filename); $doc = new DOMDocument(); $doc->loadXML($xml); // Parses Description Tag and Remove help and File Descriptor $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; } // Selects Seed from $seeds shuffle($seeds); $seed = $seeds[mt_rand(0, count($seeds)-1)]; unset($seeds); // Makes a Double Precision Number or Floating Point $parts = explode(' ', $seed); foreach($parts as $key => $value) if (!is_numeric($value) && is_string($value)) unset($parts[$key]); shuffle($parts); $keys = array_keys($parts); switch((string)mt_rand(0,11)) { default: $float = ($parts[$keys[mt_rand(0, count($keys)-1)]] * sqrt(microtime(true))); break; case "1": $float = ($parts[$keys[mt_rand(0, count($keys)-1)]] / sqrt(microtime(true))); break; case "2": $float = ($parts[$keys[mt_rand(0, count($keys)-1)]] - sqrt(microtime(true))); break; case "3": $float = ($parts[$keys[mt_rand(0, count($keys)-1)]] + sqrt(microtime(true))); break; case "4": $float = (sqrt($parts[$keys[mt_rand(0, count($keys)-1)]]) * microtime(true)); break; case "5": $float = (sqrt($parts[$keys[mt_rand(0, count($keys)-1)]]) / microtime(true)); break; case "6": $float = (sqrt($parts[$keys[mt_rand(0, count($keys)-1)]]) - microtime(true)); break; case "7": $float = (sqrt($parts[$keys[mt_rand(0, count($keys)-1)]]) + microtime(true)); break; case "8": $float = (sqrt($parts[$keys[mt_rand(0, count($keys)-1)]]) * sqrt(microtime(true))); break; case "9": $float = (sqrt($parts[$keys[mt_rand(0, count($keys)-1)]]) / sqrt(microtime(true))); break; case "10": $float = (sqrt($parts[$keys[mt_rand(0, count($keys)-1)]]) - sqrt(microtime(true))); break; case "11": $float = (sqrt($parts[$keys[mt_rand(0, count($keys)-1)]]) + sqrt(microtime(true))); break; } unset($keys); unset($parts); // Constructs Integer from Floating Point/Double $parts = explode(".", $float); if (count($parts)==2) { switch((string)mt_rand(0,5)) { default: $int = (integer)$float; break; case "1": $int = $parts[0] * $parts[1]; break; case "2": $int = $parts[0] . $parts[1]; break; case "3": $int = $parts[1] . $parts[0]; break; case "4": $int = (integer)($parts[1] / $parts[0]); break; case "5": $int = (integer)($parts[0] / $parts[1]); break; } } else { $int = (integer)$float; } // Randomise the Seeding with Integer mt_rand($int); if (!headers_sent()) header('Context-seed: ' . sha1($int)); return $int; } ?> ---- Server IP: 27.50.85.3 Probable Submitter: 203.206.220.82 ---- Manual Page -- http://php.net/manual/en/function.mt-srand.php Edit -- https://master.php.net/note/edit/114019 Del: integrated -- https://master.php.net/note/delete/114019/integrated Del: useless -- https://master.php.net/note/delete/114019/useless Del: bad code -- https://master.php.net/note/delete/114019/bad+code Del: spam -- https://master.php.net/note/delete/114019/spam Del: non-english -- https://master.php.net/note/delete/114019/non-english Del: in docs -- https://master.php.net/note/delete/114019/in+docs Del: other reasons-- https://master.php.net/note/delete/114019 Reject -- https://master.php.net/note/reject/114019 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#198064) next »