예제 #1
0
 public function testFailureOnNonExistentInitFile()
 {
     #> Given
     $twister = new twister();
     $exception = NULL;
     #> When
     try {
         $twister->init_with_file($this->getNonExistentFile());
     } catch (Exception $exception) {
     }
     #> Then
     $this->assertNotNull($exception);
 }
예제 #2
0
for ($i = 0; $i < $num_iters; $i++) {
    $sum += $twister3->rangereal_halfopen(10, 20);
}
/*
  the call to rangereal_halfopen produces a
  floating-point number >= 10 and < 20
*/
print "This is the average, " . "which should be about 15: " . $sum / $num_iters . "\n";
$twister3 = unserialize($saved);
# run the loop again
#
$sum = 0;
for ($i = 0; $i < $num_iters; $i++) {
    $sum += $twister3->rangereal_halfopen(10, 20);
}
print "This is the average again, " . "which should be the same as before: " . $sum / $num_iters . "\n";
#--------------------------------------------
$twister4 = new twister();
$twister4->init_with_file("/dev/urandom", twister::N);
/*
  This reads characters from /dev/urandom and
  uses them to initialise the random number
  generator.

  The second argument is multiplied by 4 and
  then used as an upper bound on the number of
  characters to read.
*/
if ($twister4->rangeint(1, 6) == 6) {
    print "You've won -- congratulations!\n";
}