public function test_hex_string() { $count = 2000; $tolerance = 0.6; $buckets = array_combine(str_split('0123456789abcdef'), array_fill(0, 16, 0)); for ($i = 1; $i <= $count; $i++) { $len = mt_rand(2, 256); $str = PHPRandom::getHexString($len); $this->assertEquals($len, strlen($str)); $this->assertEquals(true, isset($buckets[$str[0]])); $buckets[$str[0]]++; } $distribution = 0; foreach ($buckets as $key => $value) { if ($value > $count / 16 * 0.5) { $distribution++; } if ($value < $count / 16 * 1.5) { $distribution++; } } $this->assertGreaterThan(16, $distribution); }
<? include_once "../config.php"; $gift = "WATER"; for ($i=0; $i < 20;$i++) { $serial = PHPRandom::getHexString("12"); $query = "INSERT INTO serial_info_(serial_code,gift) values('".$serial."','".$gift."')"; $result = mysqli_query($my_db, $query); } ?>