/**
  * Checks that resulting distribution of binary values is
  * approximately same.
  *
  * @param string $bytes to check
  */
 public static function pvalue($bytes)
 {
     $hist = array();
     // histogram
     $freq = array();
     // expected frequency
     $N = 256;
     for ($i = 0; $i < $N; $i++) {
         $hist[$i] = 0;
         $freq[$i] = 1.0 / $N;
     }
     foreach (unpack('C*', $bytes) as $char) {
         $hist[$char]++;
     }
     $chisqr = PearsonChiSquare::chiSquare($hist, $freq);
     return PearsonChiSquare::pvalue($N - 1, $chisqr);
 }
Пример #2
0
 public function testPvalueHighPrecision()
 {
     $this->assertEquals(0.9906109591, PearsonChiSquare::pvalue(3, 0.11), '', 1.0E-9);
     $this->assertEquals(0.9598403687, PearsonChiSquare::pvalue(7, 2), '', 1.0E-9);
     $this->assertEquals(0.005569683073, PearsonChiSquare::pvalue(7, 20), '', 1.0E-9);
 }