[ExRand目次]   [次:SplitMix64について]

rdrandをtestU01とPractRandで検定する

目次

testU01 と PractRand を知るために、
真の乱数に近い rdrand を testU01 と PractRand で検定してみました。
Seed(#)の#は回数を示すだけで乱数列には影響しません。
rdrand は再現性がないので、結果は検定する度に変化します。

結論

rdrandの速さについて

rdrand は第3世代以降のCPUで使用可能です。
rdrand は疑似乱数と比較して非常に遅いです。
第10世代の Core i5-10500T+Windows11 23H2 上で実行して、
このページの「testU01で検定する」の結果を得るのに3日半かかりました。
第11世代のCPUでは rdrand はさらに約40倍時間がかかります。
つまり、結果を得るのに約4か月半かかることになります。
第10世代以前のCPUでも Windows11 24H2 以降の場合、C:\Windows\System32にある
mcupdate_GenuineIntel.dll をリネームする必要があります。リネームの方法は、
日記という名の不定記 https://griffonworks.net/~yamagin/diary/archive/6854.php
が参考になります。
ただし、リネームするとOSが起動しなくなる可能性があります。
Ubuntu の場合は、
ハードウエア乱数の生成速度 https://isaku-wada.my.coocan.jp/tips/hrng.html
で説明しました。
どちらの場合もPCが脆弱になるのでお勧めできません。
自己責任でお願いします。検定が終わったら元に戻しましょう。

rnc.h

gcc, clang, vc2012 .. vc2022 でコンパイル可能です。

define.h はこちら

roc.h

roc.h は rnc.h を OpenMP でマルチスレッド化したプログラムです。

gcc, clang, vc2012 .. vc2022 でコンパイル可能です。

直前の rnc.h と define.h が必要です。

define.h はこちら

rdrandをtestU01で検定する

以下にtestU01で検定した結果の要約を示します。

type                 , c, test                     , p-value 
RocRand rawhi Seed(1), B, ClosePairs mNP2,t=3      , 4.9e-4  
RocRand rawhi Seed(2), B, CollisionOver,t=3        , 3.4e-4  
RocRand rawhi Seed(3), B, Passed                   , -       
RocRand rawhi Seed(4), B, Passed                   , -       
RocRand rawhi Seed(5), B, Passed                   , -       
RocRand rawhi Seed(6), B, Passed                   , -       
RocRand rawlo Seed(1), B, Passed                   , -       
RocRand rawlo Seed(2), B, Passed                   , -       
RocRand rawlo Seed(3), B, Passed                   , -       
RocRand rawlo Seed(4), B, Passed                   , -       
RocRand rawlo Seed(5), B, Passed                   , -       
RocRand rawlo Seed(6), B, LongestHeadRun,r=27      , 0.9995  
RocRand revhi Seed(1), B, Passed                   , -       
RocRand revhi Seed(2), B, Passed                   , -       
RocRand revhi Seed(3), B, Passed                   , -       
RocRand revhi Seed(4), B, CollisionOver,t=3        , 0.9991  
RocRand revhi Seed(5), B, RandomWalk1 R(L=1000,r=0), 2.4e-4  
-                    , B, AutoCor,d=1,r=0          , 3.5e-4  
RocRand revhi Seed(6), B, Passed                   , -       
RocRand revlo Seed(1), B, Passed                   , -       
RocRand revlo Seed(2), B, CollisionOver,t=21       , 8.6e-4  
RocRand revlo Seed(3), B, CouponCollector,r=20     , 6.2e-4  
-                    , B, RandomWalk1 M(L=50,r=25) , 8.5e-4  
RocRand revlo Seed(4), B, Passed                   , -       
RocRand revlo Seed(5), B, Passed                   , -       
RocRand revlo Seed(6), B, LempelZiv,r=15           , 1-9.9e-5
-                    , B, Run of bits,r=27         , 1.0e-3  
RocRand swphi Seed(1), B, Passed                   , -       
RocRand swphi Seed(2), B, Passed                   , -       
RocRand swphi Seed(3), B, Passed                   , -       
RocRand swphi Seed(4), B, CollisionOver,t=14       , 1-6.0e-5
RocRand swphi Seed(5), B, CollisionOver,t=7        , 0.9997  
-                    , B, SampleProd,t=16          , 2.4e-4  
RocRand swphi Seed(6), B, Passed                   , -       
RocRand swplo Seed(1), B, PeriodsInStrings,r=0     , 9.5e-4  
RocRand swplo Seed(2), B, Passed                   , -       
RocRand swplo Seed(3), B, Passed                   , -       
RocRand swplo Seed(4), B, Passed                   , -       
RocRand swplo Seed(5), B, Passed                   , -       
RocRand swplo Seed(6), B, Passed                   , -       

rawhi は64ビットの上位32ビットを検定の対象としたものです。
rawlo は64ビットの下位32ビットを検定の対象としたものです。
revhi, revlo はビット毎に順序を反転したものです。
swphi, swplo はバイト毎に順序を反転したものです。
B は BigCrush を意味します。
このように、何度も検定すると何回か異常と判断されます。

rdrandをPractRandで検定する

PractRandで rdrand を40回 1GB, 2GB, 4GB の3つの長さで、 異常のあったものを表示します。
この120回分を1つのテストとします。
-te 0 を te0、-te 1 を te1、-te 10 を te10、-tf 1 を tf1、-tf 2 を te2 と表します。
1つのテストを te0, te1, te10 と tf1, tf2 の6個の組み合わせをテストして合計720回調べました。
RocRand te0 tf1 Seed(4) 2GB  [Low16/64]BCFN(2+8,13-5,T) p=1-1.2e-5 unusual 
RocRand te0 tf1 Seed(4) 4GB  [Low4/64]mod3n(5):(2,9-6) p=5.3e-5 unusual 
RocRand te0 tf1 Seed(6) 1GB  [Low4/64]DC6-9x1Bytes-1 p=1-3.6e-3 unusual 
RocRand te0 tf1 Seed(6) 2GB  FPF-14+6/16:cross p=1-3.6e-4 unusual 
RocRand te0 tf1 Seed(8) 4GB  [Low4/64]Gap-16:A p=1-6.7e-4 unusual 
RocRand te0 tf1 Seed(10) 4GB  DC6-9x1Bytes-1 p=1-4.0e-3 unusual 
RocRand te0 tf1 Seed(15) 4GB  [Low16/64]DC6-9x1Bytes-1 p=2.1e-3 unusual 
RocRand te0 tf1 Seed(18) 4GB  [Low1/64]FPF-14+6/16:cross p=1-4.1e-4 unusual 
RocRand te0 tf1 Seed(23) 4GB  [Low4/64]mod3n(5):(1,9-6) p=1.0e-4 unusual 
RocRand te0 tf1 Seed(27) 1GB  [Low16/64]FPF-14+6/16:(14,14-8) p=4.6e-6 unusual 
RocRand te0 tf1 Seed(36) 2GB  [Low4/64]DC6-9x1Bytes-1 p=1.6e-3 unusual 
RocRand te0 tf1 Seed(37) 2GB  BCFN(2+0,13-0,T) p=1-9.6e-4 unusual 
RocRand te0 tf2 Seed(6) 1GB  [Low4/16]BCFN(2+0,13-2,T) p=5.1e-5 unusual 
RocRand te0 tf2 Seed(9) 1GB  [Low1/16]BCFN(2+3,13-4,T) p=1-1.1e-5 unusual 
RocRand te0 tf2 Seed(9) 2GB  [Low1/32]Gap-16:A p=1-2.3e-4 unusual 
RocRand te0 tf2 Seed(18) 2GB  [Low8/32]BCFN(2+0,13-1,T) p=1-3.3e-4 unusual 
RocRand te0 tf2 Seed(22) 1GB  [Low4/64]DC6-9x1Bytes-1 p=1.1e-3 unusual 
RocRand te0 tf2 Seed(35) 4GB  [Low4/16]FPF-14+6/16:cross p=1.3e-4 unusual 
RocRand te0 tf2 Seed(36) 1GB  [Low1/32]BCFN(2+3,13-5,T) p=1.5e-5 unusual 
RocRand te0 tf2 Seed(36) 1GB  [Low1/32]BCFN(2+5,13-6,T) p=1.9e-5 unusual 
RocRand te1 tf1 Seed(7) 4GB  FPF-14+6/32:all p=7.6e-5 unusual 
RocRand te1 tf1 Seed(24) 4GB  [Low16/64]mod3n(0):(3,9-6) p=1.3e-5 unusual 
RocRand te1 tf1 Seed(29) 1GB  [Low16/64]BCFN(0+0,13-1,T) p=1-1.5e-4 unusual 
RocRand te1 tf1 Seed(30) 4GB  [Low4/64]BCFN(0+3,13-2,T) p=1-1.5e-4 unusual 
RocRand te1 tf1 Seed(31) 1GB  [Low16/64]BCFN(0+4,13-3,T) p=1-8.0e-5 unusual 
RocRand te1 tf1 Seed(31) 4GB  [Low1/64]DC7-9x1Bytes-1:both p=1.1e-3 unusual 
RocRand te1 tf1 Seed(37) 1GB  BCFN(0+0,13-0,T) p=1-5.8e-5 unusual 
RocRand te1 tf2 Seed(9) 4GB  [Low4/32]DC7-5x4Bytes-1:indep p=1-1e-4 unusual 
RocRand te1 tf2 Seed(14) 1GB  [Low1/16]BCFN(0+4,13-4,T) p=1-6.0e-5 unusual 
RocRand te1 tf2 Seed(20) 4GB  [Low4/16]BCFN(0+3,13-1,T) p=9.4e-5 unusual 
RocRand te1 tf2 Seed(29) 1GB  [Low4/16]DC7-5x4Bytes-1:indep p=1-4e-5 unusual 
RocRand te1 tf2 Seed(34) 4GB  [Low1/64]DC7-9x1Bytes-1:odd p=1.9e-4 unusual 
RocRand te10 tf1 Seed(4) 2GB  [Low1/64]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf1 Seed(7) 4GB  BDayS128(26):all1 p=1e-3 unusual 
RocRand te10 tf1 Seed(7) 4GB  BDayS128(26):all2 p=6e-5 suspicious 
RocRand te10 tf1 Seed(12) 2GB  BDayS128(26):all2 p=3e-3 unusual 
RocRand te10 tf1 Seed(13) 4GB  [Low4/64]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(1) 2GB  [Low4/32]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(1) 4GB  [Low1/16]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(4) 1GB  [Low1/8]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(5) 4GB  [Low1/8]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(7) 1GB  [Low4/16]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(7) 2GB  [Low1/32]BDayS128(26):inc1 p=2e-3 unusual 
RocRand te10 tf2 Seed(7) 2GB  [Low1/32]BDayS128(26):inc2 p=9e-12 FAIL 
RocRand te10 tf2 Seed(7) 2GB  [Low4/16]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(10) 1GB  [Low1/32]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(10) 1GB  [Low1/64]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(10) 4GB  [Low1/64]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(13) 1GB  [Low1/64]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(13) 2GB  [Low1/16]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(15) 1GB  [Low1/64]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(15) 2GB  [Low1/16]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(17) 1GB  BDayS128(26):all2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(17) 4GB  BDayS128(26):all2 p=2e-3 unusual 
RocRand te10 tf2 Seed(17) 4GB  [Low1/8]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(25) 2GB  [Low8/32]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(27) 1GB  [Low4/64]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(32) 4GB  [Low8/32]BDayS128(26):all2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(33) 2GB  [Low4/16]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(33) 2GB  [Low8/32]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(33) 4GB  [Low1/64]BDayS128(26):inc1 p=2e-3 unusual 
RocRand te10 tf2 Seed(33) 4GB  [Low1/64]BDayS128(26):inc2 p=9e-12 FAIL 
RocRand te10 tf2 Seed(34) 2GB  [Low1/64]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(34) 4GB  [Low4/16]BDayS128(26):all2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(34) 4GB  [Low4/32]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(35) 2GB  [Low1/64]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(35) 4GB  [Low1/64]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(36) 4GB  [Low1/32]BDayS128(26):inc1 p=2e-3 unusual 
RocRand te10 tf2 Seed(36) 4GB  [Low1/32]BDayS128(26):inc2 p=9e-12 FAIL 
RocRand te10 tf2 Seed(38) 1GB  [Low1/8]BDayS128(26):inc1 p=2e-3 unusual 
RocRand te10 tf2 Seed(38) 1GB  [Low1/8]BDayS128(26):inc2 p=9e-12 FAIL 
RocRand te10 tf2 Seed(38) 1GB  [Low4/32]BDayS128(26):inc2 p=8e-6 suspicious 
RocRand te10 tf2 Seed(39) 8GB  [Low4/64]BDayS128(26):inc2 p=8e-6 suspicious 

te10 を指定すると te0 や te1 に比べてかなりの頻度で非常に 悪い結果が多く出現します。

rdrand に欠陥がある可能性があると考えて、PractRand でお勧めの sfc64 でも te10 でテストしてみました。
(gawk.exe を自分で用意してください。 example の「tee sfc64-te10-tf2.txt」は省略可能です。)

sfc64 Seed 0x2 te10 tf1 2GB  BDayS128(26):all2 p=3e-3 unusual 
sfc64 Seed 0x9 te10 tf1 2GB  [Low1/64]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x11 te10 tf1 1GB  [Low16/64]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x16 te10 tf1 4GB  [Low16/64]BDayS128(26):all2 p=8e-6 suspicious 
sfc64 Seed 0x18 te10 tf1 2GB  [Low4/64]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x19 te10 tf1 2GB  BDayS128(26):all2 p=3e-3 unusual 
sfc64 Seed 0x19 te10 tf1 2GB  [Low16/64]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x1a te10 tf1 2GB  [Low4/64]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x1f te10 tf1 1GB  [Low1/64]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x1f te10 tf1 2GB  [Low1/64]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x26 te10 tf1 4GB  [Low4/64]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x5 te10 tf2 4GB  [Low1/8]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x7 te10 tf2 2GB  [Low1/16]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x7 te10 tf2 4GB  [Low1/16]BDayS128(26):inc1 p=2e-3 unusual 
sfc64 Seed 0x7 te10 tf2 4GB  [Low1/16]BDayS128(26):inc2 p=9e-12 FAIL 
sfc64 Seed 0x9 te10 tf2 2GB  [Low1/64]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0xa te10 tf2 2GB  [Low8/32]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x11 te10 tf2 2GB  [Low1/32]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x12 te10 tf2 4GB  [Low4/32]BDayS128(26):inc1 p=3e-4 unusual 
sfc64 Seed 0x12 te10 tf2 4GB  [Low4/32]BDayS128(26):inc2 p=6e-18 FAIL ! 
sfc64 Seed 0x15 te10 tf2 4GB  [Low1/8]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x16 te10 tf2 4GB  [Low8/32]BDayS128(26):all2 p=8e-6 suspicious 
sfc64 Seed 0x17 te10 tf2 1GB  [Low8/32]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x18 te10 tf2 1GB  [Low1/8]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x18 te10 tf2 2GB  [Low4/64]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x1a te10 tf2 2GB  [Low4/64]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x1b te10 tf2 4GB  [Low8/64]BDayS128(26):inc1 p=2e-3 unusual 
sfc64 Seed 0x1b te10 tf2 4GB  [Low8/64]BDayS128(26):inc2 p=9e-12 FAIL 
sfc64 Seed 0x1c te10 tf2 1GB  [Low4/32]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x1e te10 tf2 2GB  [Low1/16]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x1f te10 tf2 1GB  [Low1/64]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x1f te10 tf2 2GB  [Low1/64]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x20 te10 tf2 4GB  [Low1/32]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x21 te10 tf2 1GB  [Low4/16]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x21 te10 tf2 2GB  [Low8/64]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x22 te10 tf2 2GB  [Low1/16]BDayS128(26):inc2 p=8e-6 suspicious 
sfc64 Seed 0x26 te10 tf2 1GB  [Low8/64]BDayS128(26):inc1 p=2e-3 unusual 
sfc64 Seed 0x26 te10 tf2 1GB  [Low8/64]BDayS128(26):inc2 p=9e-12 FAIL 
te10 でテストした場合、suspicious や FAIL と判定されても その乱数が悪いとは限らないことが分かりました。

rnb.h

多くのコンパイラでコンパイル可能です。

define.h, bincode.h はこちら

rob.h

OpenMP が必要なため、Visual C++ では 2005 からコンパイル可能です。
直前の rnb.h と define.h, bincode.h が必要です。

define.h, bincode.h はこちら

[ExRand目次]   [次:SplitMix64について]