PHP Classes

File: Rand.php

Recommend this page to a friend!
  Classes of freak   Rand   Rand.php   Download  
File: Rand.php
Role: Class source
Content type: text/plain
Description: this is the only file
Class: Rand
Generate random numbers
Author: By
Last change: A little bit more efficient algorithm. :)
Date: 15 years ago
Size: 1,035 bytes
 

Contents

Class file image Download
<?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;
        }
    }
?>