Skip to content

Instantly share code, notes, and snippets.

@tom--
Last active July 27, 2016 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tom--/7311a6fb3bfd00a9f527bb80ac27d668 to your computer and use it in GitHub Desktop.
Save tom--/7311a6fb3bfd00a9f527bb80ac27d668 to your computer and use it in GitHub Desktop.
Statistical testing of updated mt_rand() in PHP 7.1 using PractRand and Dieharder

Statistical tests of the modified mt_rand() in PHP 7.1

The implementation of mt_rand() has changed in PHP 7.1.0beta1

Among other things, bugs #71152 and #45184 were fixed.

I ran the output through this version of dieharder and this version of PractRand. It is hard to test a PHP binary with TestU01 because it has no facility to accept input from stdin.

The generator mt_rand_gen.php was:

<?php

if ($argc === 2) {
    mt_srand($argv[1]);
} elseif ($argc === 3) {
    mt_srand($argv[1], $argv[2]);
}

while (true) {
    echo hex2bin(sprintf('%016x', mt_rand(~PHP_INT_MAX, PHP_INT_MAX)));
}

The statistical failures are, I believe, at the rate that we should expect.

$ ../../php-src/sapi/cli/php mt_rand_gen.php 12345678 | dieharder -g 200 -a
#=============================================================================#
# dieharder version 3.31.1 Copyright 2003 Robert G. Brown #
#=============================================================================#
rng_name |rands/second| Seed |
stdin_input_raw| 2.42e+06 | 57211265|
#=============================================================================#
test_name |ntup| tsamples |psamples| p-value |Assessment
#=============================================================================#
diehard_birthdays| 0| 100| 100|0.92379316| PASSED
diehard_operm5| 0| 1000000| 100|0.39032260| PASSED
diehard_rank_32x32| 0| 40000| 100|0.58361408| PASSED
diehard_rank_6x8| 0| 100000| 100|0.71962106| PASSED
diehard_bitstream| 0| 2097152| 100|0.81549234| PASSED
diehard_opso| 0| 2097152| 100|0.50533836| PASSED
diehard_oqso| 0| 2097152| 100|0.61168801| PASSED
diehard_dna| 0| 2097152| 100|0.61424703| PASSED
diehard_count_1s_str| 0| 256000| 100|0.37534943| PASSED
diehard_count_1s_byt| 0| 256000| 100|0.77985491| PASSED
diehard_parking_lot| 0| 12000| 100|0.03880968| PASSED
diehard_2dsphere| 2| 8000| 100|0.90907693| PASSED
diehard_3dsphere| 3| 4000| 100|0.49327059| PASSED
diehard_squeeze| 0| 100000| 100|0.76045916| PASSED
diehard_sums| 0| 100| 100|0.08434946| PASSED
diehard_runs| 0| 100000| 100|0.51664400| PASSED
diehard_runs| 0| 100000| 100|0.36714339| PASSED
diehard_craps| 0| 200000| 100|0.54729350| PASSED
diehard_craps| 0| 200000| 100|0.99769063| WEAK
marsaglia_tsang_gcd| 0| 10000000| 100|0.73535873| PASSED
marsaglia_tsang_gcd| 0| 10000000| 100|0.28959225| PASSED
sts_monobit| 1| 100000| 100|0.40958677| PASSED
sts_runs| 2| 100000| 100|0.80395418| PASSED
sts_serial| 1| 100000| 100|0.76005921| PASSED
sts_serial| 2| 100000| 100|0.66384294| PASSED
sts_serial| 3| 100000| 100|0.94036675| PASSED
sts_serial| 3| 100000| 100|0.69045868| PASSED
sts_serial| 4| 100000| 100|0.00291023| WEAK
sts_serial| 4| 100000| 100|0.00631343| PASSED
sts_serial| 5| 100000| 100|0.45003844| PASSED
sts_serial| 5| 100000| 100|0.69693591| PASSED
sts_serial| 6| 100000| 100|0.60278934| PASSED
sts_serial| 6| 100000| 100|0.78337263| PASSED
sts_serial| 7| 100000| 100|0.47181561| PASSED
sts_serial| 7| 100000| 100|0.76019328| PASSED
sts_serial| 8| 100000| 100|0.97610699| PASSED
sts_serial| 8| 100000| 100|0.91307689| PASSED
sts_serial| 9| 100000| 100|0.97012748| PASSED
sts_serial| 9| 100000| 100|0.50769555| PASSED
sts_serial| 10| 100000| 100|0.26875965| PASSED
sts_serial| 10| 100000| 100|0.23453192| PASSED
sts_serial| 11| 100000| 100|0.34660231| PASSED
sts_serial| 11| 100000| 100|0.72972534| PASSED
sts_serial| 12| 100000| 100|0.87329273| PASSED
sts_serial| 12| 100000| 100|0.85978299| PASSED
sts_serial| 13| 100000| 100|0.69280534| PASSED
sts_serial| 13| 100000| 100|0.23464562| PASSED
sts_serial| 14| 100000| 100|0.21595123| PASSED
sts_serial| 14| 100000| 100|0.91560578| PASSED
sts_serial| 15| 100000| 100|0.12786031| PASSED
sts_serial| 15| 100000| 100|0.19522672| PASSED
sts_serial| 16| 100000| 100|0.98729027| PASSED
sts_serial| 16| 100000| 100|0.33920939| PASSED
rgb_bitdist| 1| 100000| 100|0.39413185| PASSED
rgb_bitdist| 2| 100000| 100|0.14923097| PASSED
rgb_bitdist| 3| 100000| 100|0.68525169| PASSED
rgb_bitdist| 4| 100000| 100|0.65108325| PASSED
rgb_bitdist| 5| 100000| 100|0.24416272| PASSED
rgb_bitdist| 6| 100000| 100|0.02536277| PASSED
rgb_bitdist| 7| 100000| 100|0.55950541| PASSED
rgb_bitdist| 8| 100000| 100|0.02346330| PASSED
rgb_bitdist| 9| 100000| 100|0.18467636| PASSED
rgb_bitdist| 10| 100000| 100|0.38148906| PASSED
rgb_bitdist| 11| 100000| 100|0.61294649| PASSED
rgb_bitdist| 12| 100000| 100|0.92977186| PASSED
rgb_minimum_distance| 2| 10000| 1000|0.75905751| PASSED
rgb_minimum_distance| 3| 10000| 1000|0.18061776| PASSED
rgb_minimum_distance| 4| 10000| 1000|0.08424104| PASSED
rgb_minimum_distance| 5| 10000| 1000|0.21458682| PASSED
rgb_permutations| 2| 100000| 100|0.97707747| PASSED
rgb_permutations| 3| 100000| 100|0.92865102| PASSED
rgb_permutations| 4| 100000| 100|0.81179340| PASSED
rgb_permutations| 5| 100000| 100|0.49577440| PASSED
rgb_lagged_sum| 0| 1000000| 100|0.49494656| PASSED
rgb_lagged_sum| 1| 1000000| 100|0.30416513| PASSED
rgb_lagged_sum| 2| 1000000| 100|0.96520316| PASSED
rgb_lagged_sum| 3| 1000000| 100|0.72632365| PASSED
rgb_lagged_sum| 4| 1000000| 100|0.49366431| PASSED
rgb_lagged_sum| 5| 1000000| 100|0.09441503| PASSED
rgb_lagged_sum| 6| 1000000| 100|0.89488594| PASSED
rgb_lagged_sum| 7| 1000000| 100|0.83559752| PASSED
rgb_lagged_sum| 8| 1000000| 100|0.17868475| PASSED
rgb_lagged_sum| 9| 1000000| 100|0.27480036| PASSED
rgb_lagged_sum| 10| 1000000| 100|0.56511453| PASSED
rgb_lagged_sum| 11| 1000000| 100|0.42015551| PASSED
rgb_lagged_sum| 12| 1000000| 100|0.08194851| PASSED
rgb_lagged_sum| 13| 1000000| 100|0.37818394| PASSED
rgb_lagged_sum| 14| 1000000| 100|0.51604331| PASSED
rgb_lagged_sum| 15| 1000000| 100|0.82615154| PASSED
rgb_lagged_sum| 16| 1000000| 100|0.34349726| PASSED
rgb_lagged_sum| 17| 1000000| 100|0.04168468| PASSED
rgb_lagged_sum| 18| 1000000| 100|0.30704345| PASSED
rgb_lagged_sum| 19| 1000000| 100|0.29702974| PASSED
rgb_lagged_sum| 20| 1000000| 100|0.43515219| PASSED
rgb_lagged_sum| 21| 1000000| 100|0.26167180| PASSED
rgb_lagged_sum| 22| 1000000| 100|0.01483867| PASSED
rgb_lagged_sum| 23| 1000000| 100|0.92576849| PASSED
rgb_lagged_sum| 24| 1000000| 100|0.43815820| PASSED
rgb_lagged_sum| 25| 1000000| 100|0.02773936| PASSED
rgb_lagged_sum| 26| 1000000| 100|0.02961539| PASSED
rgb_lagged_sum| 27| 1000000| 100|0.33371794| PASSED
rgb_lagged_sum| 28| 1000000| 100|0.76971950| PASSED
rgb_lagged_sum| 29| 1000000| 100|0.58915334| PASSED
rgb_lagged_sum| 30| 1000000| 100|0.00106644| WEAK
rgb_lagged_sum| 31| 1000000| 100|0.33687349| PASSED
rgb_lagged_sum| 32| 1000000| 100|0.85300601| PASSED
rgb_kstest_test| 0| 10000| 1000|0.83031382| PASSED
dab_bytedistrib| 0| 51200000| 1|0.29266452| PASSED
dab_dct| 256| 50000| 1|0.87660307| PASSED
Preparing to run test 207. ntuple = 0
dab_filltree| 32| 15000000| 1|0.02416103| PASSED
dab_filltree| 32| 15000000| 1|0.11715797| PASSED
Preparing to run test 208. ntuple = 0
dab_filltree2| 0| 5000000| 1|0.48146078| PASSED
dab_filltree2| 1| 5000000| 1|0.72736339| PASSED
Preparing to run test 209. ntuple = 0
dab_monobit2| 12| 65000000| 1|0.70663653| PASSED
$ ../../php-src/sapi/cli/php mt_rand_gen.php 12345678 | ../PractRand/RNG_test stdin64
RNG = RNG_stdin64, PractRand version 0.92, seed = 0xe0bdd74e
test set = normal, folding = standard (64 bit)
rng=RNG_stdin64, seed=0xe0bdd74e
length= 16 megabytes (2^24 bytes), time= 3.0 seconds
no anomalies in 116 test result(s)
rng=RNG_stdin64, seed=0xe0bdd74e
length= 32 megabytes (2^25 bytes), time= 11.2 seconds
no anomalies in 127 test result(s)
rng=RNG_stdin64, seed=0xe0bdd74e
length= 64 megabytes (2^26 bytes), time= 23.9 seconds
Test Name Raw Processed Evaluation
[Low1/64]BCFN(2+2,13-8,T) R= -4.4 p =1-6.7e-4 unusual
...and 136 test result(s) without anomalies
rng=RNG_stdin64, seed=0xe0bdd74e
length= 128 megabytes (2^27 bytes), time= 56.8 seconds
no anomalies in 148 test result(s)
rng=RNG_stdin64, seed=0xe0bdd74e
length= 256 megabytes (2^28 bytes), time= 104 seconds
Test Name Raw Processed Evaluation
DC6-9x1Bytes-1 R= -4.3 p =1-4.0e-3 unusual
[Low4/64]DC6-9x1Bytes-1 R= +5.9 p = 3.9e-3 unusual
...and 157 test result(s) without anomalies
rng=RNG_stdin64, seed=0xe0bdd74e
length= 512 megabytes (2^29 bytes), time= 189 seconds
no anomalies in 169 test result(s)
rng=RNG_stdin64, seed=0xe0bdd74e
length= 1 gigabyte (2^30 bytes), time= 374 seconds
Test Name Raw Processed Evaluation
[Low1/64]Gap-16:B R= +4.4 p = 9.6e-4 unusual
...and 179 test result(s) without anomalies
rng=RNG_stdin64, seed=0xe0bdd74e
length= 2 gigabytes (2^31 bytes), time= 670 seconds
no anomalies in 191 test result(s)
rng=RNG_stdin64, seed=0xe0bdd74e
length= 4 gigabytes (2^32 bytes), time= 1441 seconds
no anomalies in 201 test result(s)
rng=RNG_stdin64, seed=0xe0bdd74e
length= 8 gigabytes (2^33 bytes), time= 3042 seconds
no anomalies in 212 test result(s)
rng=RNG_stdin64, seed=0xe0bdd74e
length= 16 gigabytes (2^34 bytes), time= 6259 seconds
no anomalies in 223 test result(s)
rng=RNG_stdin64, seed=0xe0bdd74e
length= 32 gigabytes (2^35 bytes), time= 12794 seconds
no anomalies in 233 test result(s)
rng=RNG_stdin64, seed=0xe0bdd74e
length= 64 gigabytes (2^36 bytes), time= 25923 seconds
no anomalies in 244 test result(s)
rng=RNG_stdin64, seed=0xe0bdd74e
length= 128 gigabytes (2^37 bytes), time= 51734 seconds
no anomalies in 255 test result(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment