示例#1
0
 public function testRandom()
 {
     for ($i = 0; $i < 10; $i++) {
         $rnd = CMathf::random();
         $this->assertTrue(0.0 <= $rnd && $rnd < 1.0);
     }
 }
示例#2
0
 /**
  * Returns a random number in the specified range.
  *
  * The values of both of the parameters can possibly be returned by the method.
  *
  * The algorithm behind the random number generator is Mersenne twister.
  *
  * @param  number $min The lower bound of the range, inclusively.
  * @param  number $max The higher bound of the range, inclusively.
  *
  * @return int A random number from the range specified.
  */
 public static function intervalRandom($min, $max)
 {
     assert('is_number($min) && is_number($max)', vs(isset($this), get_defined_vars()));
     $intMin = (int) $min;
     $intMax = (int) $max;
     return $intMin + (int) (($intMax - $intMin + 1) * CMathf::random());
 }