For those who want a quick workaround, I can suggest adding this to the beginning of the test:
function Random(X: SizeInt): SizeInt; begin Result := Round(System.Random * X); end;
This still fails when SizeInt has 64 bit and L is large. As a test please consider this adapted version of the 64-bit program (i am using the 64-bit compiler, so sizeint has 64-bit):And where fails? I've added my function to both your implementations. Everything was compiled and started without problems. And the distribution became about 0.5.
// Perform rejection sampling repeat Result := ((UInt64(GenRand32) shl 32) or UInt64(GenRand32)); until Result <= thr;
It only produces even numbers for large L. You can test it against the 64 bit program when you change the condition to random(l) mod 2 = 0.That's expected. The accuracy of fraction part for double is 52, for large numbers only the exponent is used.
My personal opinion on the timing part is: The underlying PRNG is not cryptographically secure in any way, so securing the random number generation against side channel attacks does not really help.It is not secure,
I don't think it is necessary to harden random against timing attacks. It is not designed to be used as cryptographic primitive.Correct. That's not its purpose.
it's preferable to use a more advanced algorithm like ToreI googled this algorithm and apparently this is a way to construct low discrepancy sequences by taking the fractional part of multiplies of irrational numbers (e.g. the square roots of primes). Is this correct?
========= Summary results of SmallCrush =========
Version: TestU01 1.2.3
Generator: TMulSampler
Number of statistics: 15
Total CPU time: 00:00:41.60
The following tests gave p-values outside [0.001, 0.9990]:
(eps means a value < 1.0e-300):
(eps1 means a value < 1.0e-15):
Test p-value
----------------------------------------------
3 Gap eps
4 SimpPoker eps
5 CouponCollector eps
7 WeightDistrib eps
9 HammingIndep eps
10 RandomWalk1 H eps
10 RandomWalk1 M eps
10 RandomWalk1 J eps
10 RandomWalk1 C 2.5e-5
----------------------------------------------
All other tests were passed
========= Summary results of SmallCrush =========
Version: TestU01 1.2.3
Generator: TModSampler
Number of statistics: 15
Total CPU time: 00:00:41.26
The following tests gave p-values outside [0.001, 0.9990]:
(eps means a value < 1.0e-300):
(eps1 means a value < 1.0e-15):
Test p-value
----------------------------------------------
2 Collision eps
6 MaxOft eps
6 MaxOft AD 1 - eps1
7 WeightDistrib eps
9 HammingIndep 5.6e-16
10 RandomWalk1 H eps
10 RandomWalk1 M eps
10 RandomWalk1 J eps
10 RandomWalk1 R eps
10 RandomWalk1 C eps
----------------------------------------------
All other tests were passed
TMulSampler refers to the multiply and shift method and TModSampler refers to the modulo maping, both (at least in a somewhat similar form) currently implemented in the RTL.