User Tools

Site Tools


development:testing_and_prng

Testing, Reproducibility and Random Numbers

General

Software needs testing .. and many tests can be automized with unittests - or integration tests.
The program/test should be reproducible to allow (later) debugging/fixing.

Crash early!

Especially when the program or it's results must be reliable, crashing early might be advised!
In this case, additional checks should be enforced and executed. Note, that the C assert() is removed in non-debug compiled binaries.

Besides executing explicitly programmed checks, there are also other possibilities:

A welcomed side effect of crashing early:
the stack trace and the visible variable contents might reveal the initial cause of the problem
- at least with a much higher probability than after having continued and covered the problem.

Core-Dumps

A core-dump / minidump mechanism might be of interest.
For tracking very rare or specific errors, this mechanism might also get delivered to customers.

Pseudo Random Number Generators (PRNG)

For tests, a huge amount of 'random' numbers can be generated, from one seed-number.
There's no need to have a cryptographically safe PRNG.
Test with defined seed-numbers or simply log/save the used seed number.

Algorithms / Libraries

Properties

  • size of the seed or state
    • small size is of interest to use one PRNG per thread
  • quick initialization from seed
  • speed, for producing next number
  • period size - until the sequence repeats

Linear congruential generator (LCG)

LCG is perhaps the simplest (and fastest) algorithm with a small seed; see https://en.wikipedia.org/wiki/Linear_congruential_generator

Fast skipping might be of interest; see https://www.nayuki.io/page/fast-skipping-in-a-linear-congruential-generator

Xorshift

Mersenne Twister

This PRNG got hyped in the C++ community for it's ridiculously huge period size - but has a big seed size and it's initialization isn't the fastest. IMHO, in most applications, the huge period size isn't necessary.

Anyway, here a link to a SIMD-oriented implementation: http://www.math.sci.hiroshima-u.ac.jp/m-mat/MT/SFMT/index.html

development/testing_and_prng.txt · Last modified: 2023/01/08 (external edit)