Skip to content

Instantly share code, notes, and snippets.

@jos3000
Created April 9, 2010 16:59
Show Gist options
  • Save jos3000/361366 to your computer and use it in GitHub Desktop.
Save jos3000/361366 to your computer and use it in GitHub Desktop.
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