<?php class Rand { protected $ret, $tracer, $micro, $sec, $FLOAT, $MUL, $precisement;
public function frand($to=100, $from=0, $if_float=0, $if_abs=true, $if_trace=false) { $to++; $this->tracer = microtime(); list($this->micro, $this->sec) = explode(" ", $this->tracer); $this->tracer = ' - '.$this->tracer; $this->FLOAT = ''; $this->MUL = 1; if ($if_float > 0) {$to--; $this->FLOAT = '.'.frand(pow(10, $if_float));} if ($if_trace === false) { $this->tracer = '';} if ($if_abs === false) { $this->MUL = frand(2) == 0 ? -1 : 1; } $this->micro = pow($this->micro, 2) + $this->micro +41; // according to Euler's formula $this->sec = pow($this->sec, 2) + $this->sec +41; $this->precisement = strlen($to) +substr($this->micro, 0, 2) +2; $this->ret = sprintf("%.{$this->precisement}f", ($this->micro/$this->sec)); $this->ret = ((((substr($this->ret, (strlen($to) > 3 ? (5+strlen($to))*(-1) : -5)) % ($to-$from)) + $from).$this->FLOAT)*$this->MUL).$this->tracer; return $this->ret; } } ?>
|