TRandom3 - randomness test

Hello,
I’m taking an exam about statistical analysis and I have to generate random number and then submit them to a randomness test. I’m generating pseudo-random number with the TRandom3 generator, since I read that is a robust generator with a very large period. As concerns the randomness test I’m using the testing suite dieharder. In the following the source code for the generation of pseudo-random numbers.

// c++ -o die_trandom3 die_trandom3.cpp `root-config --libs --glibs --cflags`
#include "TRandom3.h"
#include <climits>
#include <iostream>

int main(int argc, char** argv){

    TRandom3* r = new TRandom3();

    unsigned long long int rnd_num = r->Uniform(-ULONG_MAX,ULONG_MAX);

    std::cout.write(reinterpret_cast<char*>(&rnd_num), sizeof rnd_num);

    while(1){

    rnd_num = r->Uniform(-ULONG_MAX,ULONG_MAX);
    //std::cout << rnd_num << std::endl;
    std::cout.write(reinterpret_cast<char*>(&rnd_num), sizeof rnd_num);

    }
    return 0;
}

And then I’m passing the random numbers into the dieharder suite using the piping, in this way:

>./die_trandom3 |dieharder -a -g 200
Where the arguments -a -g run all the tests with standard/default options to create a
user-controllable report. While the argument 200 stands for the type of input passed to dieharder, in this case a raw binary input.
Looking at the results, the TRandom3 generator fails almost every test, as described in the following output:

#=============================================================================#
#            dieharder version 3.31.1 Copyright 2003 Robert G. Brown          #
#=============================================================================#
   rng_name    |rands/second|   Seed   |
stdin_input_raw|  2.06e+07  | 261925433|
#=============================================================================#
        test_name   |ntup| tsamples |psamples|  p-value |Assessment
#=============================================================================#
   diehard_birthdays|   0|       100|     100|0.00000000|  FAILED  
      diehard_operm5|   0|   1000000|     100|0.00000000|  FAILED  
  diehard_rank_32x32|   0|     40000|     100|0.00000000|  FAILED  
    diehard_rank_6x8|   0|    100000|     100|0.00000000|  FAILED  
   diehard_bitstream|   0|   2097152|     100|0.00000000|  FAILED  
        diehard_opso|   0|   2097152|     100|0.00000000|  FAILED  
        diehard_oqso|   0|   2097152|     100|0.00000000|  FAILED  
         diehard_dna|   0|   2097152|     100|0.00000000|  FAILED  
diehard_count_1s_str|   0|    256000|     100|0.00000000|  FAILED  
diehard_count_1s_byt|   0|    256000|     100|0.00000000|  FAILED  
 diehard_parking_lot|   0|     12000|     100|0.00000000|  FAILED  
    diehard_2dsphere|   2|      8000|     100|0.00000000|  FAILED  
    diehard_3dsphere|   3|      4000|     100|0.88784058|  PASSED  
     diehard_squeeze|   0|    100000|     100|0.00000000|  FAILED  
        diehard_sums|   0|       100|     100|0.00000000|  FAILED  
        diehard_runs|   0|    100000|     100|0.00000000|  FAILED  
        diehard_runs|   0|    100000|     100|0.00000000|  FAILED  
       diehard_craps|   0|    200000|     100|0.00000000|  FAILED  
       diehard_craps|   0|    200000|     100|0.00000000|  FAILED  
 marsaglia_tsang_gcd|   0|  10000000|     100|0.00000000|  FAILED  
 marsaglia_tsang_gcd|   0|  10000000|     100|0.04028199|  PASSED  
         sts_monobit|   1|    100000|     100|0.00000000|  FAILED  
            sts_runs|   2|    100000|     100|0.00000000|  FAILED  
          sts_serial|   1|    100000|     100|0.00000000|  FAILED  
          sts_serial|   2|    100000|     100|0.00000000|  FAILED  
          sts_serial|   3|    100000|     100|0.00000000|  FAILED  
          sts_serial|   3|    100000|     100|0.00000000|  FAILED  
          sts_serial|   4|    100000|     100|0.00000000|  FAILED  
          sts_serial|   4|    100000|     100|0.00000000|  FAILED  
          sts_serial|   5|    100000|     100|0.00000000|  FAILED  
          sts_serial|   5|    100000|     100|0.00000000|  FAILED  
          sts_serial|   6|    100000|     100|0.00000000|  FAILED  
          sts_serial|   6|    100000|     100|0.00000000|  FAILED  
          sts_serial|   7|    100000|     100|0.00000000|  FAILED  
          sts_serial|   7|    100000|     100|0.00000000|  FAILED  
          sts_serial|   8|    100000|     100|0.00000000|  FAILED  
          sts_serial|   8|    100000|     100|0.00000000|  FAILED  
          sts_serial|   9|    100000|     100|0.00000000|  FAILED  
          sts_serial|   9|    100000|     100|0.00000000|  FAILED  
          sts_serial|  10|    100000|     100|0.00000000|  FAILED  
          sts_serial|  10|    100000|     100|0.00000000|  FAILED  
          sts_serial|  11|    100000|     100|0.00000000|  FAILED  
          sts_serial|  11|    100000|     100|0.00000000|  FAILED  
          sts_serial|  12|    100000|     100|0.00000000|  FAILED  
          sts_serial|  12|    100000|     100|0.00000000|  FAILED  
          sts_serial|  13|    100000|     100|0.00000000|  FAILED  
          sts_serial|  13|    100000|     100|0.00000000|  FAILED  
          sts_serial|  14|    100000|     100|0.00000000|  FAILED  
          sts_serial|  14|    100000|     100|0.00000000|  FAILED  
          sts_serial|  15|    100000|     100|0.00000000|  FAILED  
          sts_serial|  15|    100000|     100|0.00000000|  FAILED  
          sts_serial|  16|    100000|     100|0.00000000|  FAILED  
          sts_serial|  16|    100000|     100|0.00000000|  FAILED  
         rgb_bitdist|   1|    100000|     100|0.00000000|  FAILED  
         rgb_bitdist|   2|    100000|     100|0.00000000|  FAILED  
         rgb_bitdist|   3|    100000|     100|0.00000000|  FAILED  
         rgb_bitdist|   4|    100000|     100|0.00000000|  FAILED  
         rgb_bitdist|   5|    100000|     100|0.00000000|  FAILED  
         rgb_bitdist|   6|    100000|     100|0.00000000|  FAILED  
         rgb_bitdist|   7|    100000|     100|0.00000000|  FAILED  
         rgb_bitdist|   8|    100000|     100|0.00000000|  FAILED  
         rgb_bitdist|   9|    100000|     100|0.00000000|  FAILED  
         rgb_bitdist|  10|    100000|     100|0.00000000|  FAILED  
         rgb_bitdist|  11|    100000|     100|0.00000000|  FAILED  
         rgb_bitdist|  12|    100000|     100|0.00000000|  FAILED  
rgb_minimum_distance|   2|     10000|    1000|0.00000000|  FAILED  
rgb_minimum_distance|   3|     10000|    1000|0.03558598|  PASSED  
rgb_minimum_distance|   4|     10000|    1000|0.82921211|  PASSED  
rgb_minimum_distance|   5|     10000|    1000|0.04670306|  PASSED  
    rgb_permutations|   2|    100000|     100|0.00000000|  FAILED  
    rgb_permutations|   3|    100000|     100|0.00000000|  FAILED  
    rgb_permutations|   4|    100000|     100|0.00000000|  FAILED  
    rgb_permutations|   5|    100000|     100|0.00000000|  FAILED  
      rgb_lagged_sum|   0|   1000000|     100|0.00000000|  FAILED  
      rgb_lagged_sum|   1|   1000000|     100|0.95060370|  PASSED  
      rgb_lagged_sum|   2|   1000000|     100|0.00000000|  FAILED  
      rgb_lagged_sum|   3|   1000000|     100|0.49842990|  PASSED  
      rgb_lagged_sum|   4|   1000000|     100|0.00000000|  FAILED  
      rgb_lagged_sum|   5|   1000000|     100|0.44218592|  PASSED  
      rgb_lagged_sum|   6|   1000000|     100|0.00000000|  FAILED  
      rgb_lagged_sum|   7|   1000000|     100|0.65994037|  PASSED  
      rgb_lagged_sum|   8|   1000000|     100|0.00000000|  FAILED  
      rgb_lagged_sum|   9|   1000000|     100|0.59490720|  PASSED  
      rgb_lagged_sum|  10|   1000000|     100|0.00000000|  FAILED  
      rgb_lagged_sum|  11|   1000000|     100|0.99763782|   WEAK   
      rgb_lagged_sum|  12|   1000000|     100|0.00000000|  FAILED  
      rgb_lagged_sum|  13|   1000000|     100|0.02174411|  PASSED  
      rgb_lagged_sum|  14|   1000000|     100|0.00000000|  FAILED  
      rgb_lagged_sum|  15|   1000000|     100|0.79885105|  PASSED  
      rgb_lagged_sum|  16|   1000000|     100|0.00000000|  FAILED  
      rgb_lagged_sum|  17|   1000000|     100|0.96606420|  PASSED  
      rgb_lagged_sum|  18|   1000000|     100|0.00000000|  FAILED  
      rgb_lagged_sum|  19|   1000000|     100|0.19696643|  PASSED  
      rgb_lagged_sum|  20|   1000000|     100|0.00000000|  FAILED  
      rgb_lagged_sum|  21|   1000000|     100|0.46770216|  PASSED  
      rgb_lagged_sum|  22|   1000000|     100|0.00000000|  FAILED  
      rgb_lagged_sum|  23|   1000000|     100|0.28057671|  PASSED  
      rgb_lagged_sum|  24|   1000000|     100|0.00000000|  FAILED  
      rgb_lagged_sum|  25|   1000000|     100|0.84512112|  PASSED  
      rgb_lagged_sum|  26|   1000000|     100|0.00000000|  FAILED  
      rgb_lagged_sum|  27|   1000000|     100|0.97932394|  PASSED  


Then my question is: am I doing something wrong, or is it normal? Has anyone tried testing this generator?

Thank you,

Wahid

Hi,
Wahid, welcome to the ROOT forum and thank you for the interesting feedback!
The right person to address your question is @moneta, who is currently travelling and will be back in a couple of weeks. If you don’t receive an answer by then, feel free to ping us again.

In the meanwhile, looking at the docs I see that some issues with randomness tests are known for TRandom3 and TRandomMixMax is recommended as an alternative.

Cheers,
Enrico

Hi Enrico,

thank you for the quick answer!
In the meanwhile I will try the TRandomMixMax generator.
And just for feedback, the Marsenne Twister homepage linked in the docs you sent me is no more reachable.

Thanks again,
Wahid

Hi,

I think you have some issues in the way you are passing the random numbers to diehard. TRandom3 it might fail one test, but not all of them. I am not sure abouyt diehard, but I know that it fails a couple of tests of the TestU01 big crush test suite.

Looking at your code I spot immediately a problem. You are doing :

 r->Uniform(-ULONG_MAX,ULONG_MAX);

but TRandom3 is not a 64 bit generator but a 32 bit one. So you can have randomly uniform distributed integers only between [0,UINT_MAX]

Instead if you use MixMax in that case the range is [0, 2^61-1] since Mixmax is a 61 bit generator.

Lorenzo

2 Likes

I missed that TRandom3 is a 32-bit generator. This time it worked, TRandom3 passes almost all tests! In the following the results:

#=============================================================================#
#            dieharder version 3.31.1 Copyright 2003 Robert G. Brown          #
#=============================================================================#
   rng_name    |rands/second|   Seed   |
stdin_input_raw|  1.70e+07  |2242555673|
#=============================================================================#
        test_name   |ntup| tsamples |psamples|  p-value |Assessment
#=============================================================================#
   diehard_birthdays|   0|       100|     100|0.40629140|  PASSED  
      diehard_operm5|   0|   1000000|     100|0.53152825|  PASSED  
  diehard_rank_32x32|   0|     40000|     100|0.38403041|  PASSED  
    diehard_rank_6x8|   0|    100000|     100|0.74866932|  PASSED  
   diehard_bitstream|   0|   2097152|     100|0.40544717|  PASSED  
        diehard_opso|   0|   2097152|     100|0.43282000|  PASSED  
        diehard_oqso|   0|   2097152|     100|0.59129887|  PASSED  
         diehard_dna|   0|   2097152|     100|0.38517388|  PASSED  
diehard_count_1s_str|   0|    256000|     100|0.66433769|  PASSED  
diehard_count_1s_byt|   0|    256000|     100|0.97169353|  PASSED  
 diehard_parking_lot|   0|     12000|     100|0.70977074|  PASSED  
    diehard_2dsphere|   2|      8000|     100|0.29409879|  PASSED  
    diehard_3dsphere|   3|      4000|     100|0.03110855|  PASSED  
     diehard_squeeze|   0|    100000|     100|0.47118828|  PASSED  
        diehard_sums|   0|       100|     100|0.03917410|  PASSED  
        diehard_runs|   0|    100000|     100|0.96282371|  PASSED  
        diehard_runs|   0|    100000|     100|0.67148326|  PASSED  
       diehard_craps|   0|    200000|     100|0.06023367|  PASSED  
       diehard_craps|   0|    200000|     100|0.01702184|  PASSED  
 marsaglia_tsang_gcd|   0|  10000000|     100|0.12151743|  PASSED  
 marsaglia_tsang_gcd|   0|  10000000|     100|0.12230227|  PASSED  
         sts_monobit|   1|    100000|     100|0.49222693|  PASSED  
            sts_runs|   2|    100000|     100|0.22623199|  PASSED  
          sts_serial|   1|    100000|     100|0.04809104|  PASSED  
          sts_serial|   2|    100000|     100|0.21095563|  PASSED  
          sts_serial|   3|    100000|     100|0.63221253|  PASSED  
          sts_serial|   3|    100000|     100|0.63557234|  PASSED  
          sts_serial|   4|    100000|     100|0.78614170|  PASSED  
          sts_serial|   4|    100000|     100|0.89113756|  PASSED  
          sts_serial|   5|    100000|     100|0.97619918|  PASSED  
          sts_serial|   5|    100000|     100|0.98746903|  PASSED  
          sts_serial|   6|    100000|     100|0.50921995|  PASSED  
          sts_serial|   6|    100000|     100|0.83262655|  PASSED  
          sts_serial|   7|    100000|     100|0.48401391|  PASSED  
          sts_serial|   7|    100000|     100|0.78771052|  PASSED  
          sts_serial|   8|    100000|     100|0.84599025|  PASSED  
          sts_serial|   8|    100000|     100|0.67507288|  PASSED  
          sts_serial|   9|    100000|     100|0.35272463|  PASSED  
          sts_serial|   9|    100000|     100|0.24302299|  PASSED  
          sts_serial|  10|    100000|     100|0.19595265|  PASSED  
          sts_serial|  10|    100000|     100|0.14073411|  PASSED  
          sts_serial|  11|    100000|     100|0.07435980|  PASSED  
          sts_serial|  11|    100000|     100|0.03476741|  PASSED  
          sts_serial|  12|    100000|     100|0.14378596|  PASSED  
          sts_serial|  12|    100000|     100|0.11385618|  PASSED  
          sts_serial|  13|    100000|     100|0.88688573|  PASSED  
          sts_serial|  13|    100000|     100|0.24539239|  PASSED  
          sts_serial|  14|    100000|     100|0.60422387|  PASSED  
          sts_serial|  14|    100000|     100|0.34563908|  PASSED  
          sts_serial|  15|    100000|     100|0.87991159|  PASSED  
          sts_serial|  15|    100000|     100|0.25650886|  PASSED  
          sts_serial|  16|    100000|     100|0.98470992|  PASSED  
          sts_serial|  16|    100000|     100|0.87874630|  PASSED  
         rgb_bitdist|   1|    100000|     100|0.85641515|  PASSED  
         rgb_bitdist|   2|    100000|     100|0.92933162|  PASSED  
         rgb_bitdist|   3|    100000|     100|0.51244987|  PASSED  
         rgb_bitdist|   4|    100000|     100|0.84728393|  PASSED  
         rgb_bitdist|   5|    100000|     100|0.82310855|  PASSED  
         rgb_bitdist|   6|    100000|     100|0.54247080|  PASSED  
         rgb_bitdist|   7|    100000|     100|0.80333970|  PASSED  
         rgb_bitdist|   8|    100000|     100|0.00265040|   WEAK   
         rgb_bitdist|   9|    100000|     100|0.86695148|  PASSED  
         rgb_bitdist|  10|    100000|     100|0.94960922|  PASSED  
         rgb_bitdist|  11|    100000|     100|0.29025528|  PASSED  
         rgb_bitdist|  12|    100000|     100|0.53652740|  PASSED  
rgb_minimum_distance|   2|     10000|    1000|0.83730423|  PASSED  
rgb_minimum_distance|   3|     10000|    1000|0.59392927|  PASSED  
rgb_minimum_distance|   4|     10000|    1000|0.23724007|  PASSED  
rgb_minimum_distance|   5|     10000|    1000|0.00471703|   WEAK   
    rgb_permutations|   2|    100000|     100|0.96829968|  PASSED  
    rgb_permutations|   3|    100000|     100|0.79394494|  PASSED  
    rgb_permutations|   4|    100000|     100|0.49703395|  PASSED  
    rgb_permutations|   5|    100000|     100|0.47887377|  PASSED  
      rgb_lagged_sum|   0|   1000000|     100|0.32939114|  PASSED  
      rgb_lagged_sum|   1|   1000000|     100|0.62681040|  PASSED  
      rgb_lagged_sum|   2|   1000000|     100|0.68381487|  PASSED  
      rgb_lagged_sum|   3|   1000000|     100|0.25702647|  PASSED  
      rgb_lagged_sum|   4|   1000000|     100|0.54036495|  PASSED  
      rgb_lagged_sum|   5|   1000000|     100|0.02650876|  PASSED  
      rgb_lagged_sum|   6|   1000000|     100|0.37242251|  PASSED  
      rgb_lagged_sum|   7|   1000000|     100|0.77416385|  PASSED  
      rgb_lagged_sum|   8|   1000000|     100|0.05550322|  PASSED  
      rgb_lagged_sum|   9|   1000000|     100|0.25380434|  PASSED  
      rgb_lagged_sum|  10|   1000000|     100|0.16766434|  PASSED  
      rgb_lagged_sum|  11|   1000000|     100|0.07145531|  PASSED
      rgb_lagged_sum|  12|   1000000|     100|0.48163452|  PASSED  
      rgb_lagged_sum|  13|   1000000|     100|0.97923940|  PASSED  
      rgb_lagged_sum|  14|   1000000|     100|0.19260145|  PASSED  
      rgb_lagged_sum|  15|   1000000|     100|0.49309873|  PASSED  
      rgb_lagged_sum|  16|   1000000|     100|0.03533053|  PASSED  
      rgb_lagged_sum|  17|   1000000|     100|0.70601600|  PASSED  
      rgb_lagged_sum|  18|   1000000|     100|0.93404284|  PASSED  
      rgb_lagged_sum|  19|   1000000|     100|0.99404305|  PASSED  
      rgb_lagged_sum|  20|   1000000|     100|0.04990219|  PASSED  
      rgb_lagged_sum|  21|   1000000|     100|0.85254511|  PASSED  
      rgb_lagged_sum|  22|   1000000|     100|0.78350112|  PASSED  
      rgb_lagged_sum|  23|   1000000|     100|0.26719186|  PASSED  
      rgb_lagged_sum|  24|   1000000|     100|0.86354832|  PASSED  
      rgb_lagged_sum|  25|   1000000|     100|0.74678400|  PASSED 
      rgb_lagged_sum|  26|   1000000|     100|0.85100016|  PASSED
      rgb_lagged_sum|  27   1000000|     100|0.83412301|  PASSED

Thank you!

Wahid

Hi,
If you need a 64 bit generator you can use TRandomMT64, an implementation of Mersenne-Twister (as in TRandom3) but for 64 bits

Lorenzo

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.