Created
April 9, 2010 16:59
-
-
Save jos3000/361366 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Predictable { | |
private $seed; | |
public function __construct($seed){ | |
$this->seed = $seed*100; | |
} | |
#returns a predictable number based on an integer seed | |
public function pred(){ | |
$this->seed++; | |
$slice = strtoupper(substr(md5($this->seed),8,8)); | |
return abs((int)hexdec($slice)); | |
} | |
public function pred_array($array){ | |
$key = $this->pred()%count($array); | |
return $array[$key]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment