en:pfw:random_20generator_20completeness_20test
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| en:pfw:random_20generator_20completeness_20test [2023-09-04 18:18] – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | en:pfw:random_20generator_20completeness_20test [2023-09-04 18:18] (current) – ↷ Seite von pfw:random_20generator_20completeness_20test nach en:pfw:random_20generator_20completeness_20test verschoben uho | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | {{pfw: | ||
| + | ==== Random Generator Completeness Test ==== | ||
| + | |||
| + | There are many different tests to assess the quality of a random-number generator. The Diehard suite of tests from Prof. G. Marsaglia was the first in wide-spread use, and a lot more tests have been developed since. Presented here is a test for completeness. Linear Pseudorandom Number Generators have an exact amount of numbers they generate before the return to their starting point (wrap around). A good generator generates all possible numbers exactly once before wrapping around. During the development of specific variants of such generators it is useful to be able to do such a check. | ||
| + | |||
| + | The method used here is brute-force. It needs a decent CPU and at least 512 MB of continuous memory to run in a reasonable time. But a Raspberry Pi has enough memory and is fast enough to run a check in reasonable time. | ||
| + | |||
| + | == It functions thus: == | ||
| + | |||
| + | < | ||
| + | clear the 512 MB bit-array | ||
| + | reset the random generator under test | ||
| + | 4294967296 0 DO | ||
| + | get a random number from generator under test | ||
| + | set bit with generated number as index in the bit-array | ||
| + | LOOP | ||
| + | | ||
| + | reset popcount array | ||
| + | 134217728 0 DO | ||
| + | get next 32b value from array | ||
| + | do a popcount of this number | ||
| + | add 1 to the corresponding counter in the popcount array | ||
| + | LOOP | ||
| + | | ||
| + | show the popcount array in a clear way | ||
| + | </ | ||
| + | |||
| + | == Reporting the results: == | ||
| + | |||
| + | The report is the only ' | ||
| + | |||
| + | The first report shows a 32 bit LPNG which is complete: there are 134217727 population bit counts with a value of 32, and 1 popcount with a value of 31. This is exactly as expected. These generators have a period of 2< | ||
| + | |||
| + | < | ||
| + | 0=> | ||
| + | 3=> | ||
| + | 6=> | ||
| + | 9=> | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | </ | ||
| + | |||
| + | To raise complexity of a random-generator, | ||
| + | |||
| + | < | ||
| + | 0=> | ||
| + | 3=> | ||
| + | 6=> | ||
| + | 9=> | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | </ | ||
| + | |||
| + | And this is how the popcounts look with a high quality 32 bit generator with a 256 bit domain ( **xoxhiro256** from D. Blackman and S. Vigna). The normal distribution can almost be felt... | ||
| + | |||
| + | < | ||
| + | 0=> | ||
| + | | ||
| + | | ||
| + | | ||
| + | 12=> | ||
| + | 15=> | ||
| + | 18=> | ||
| + | 21=> | ||
| + | 24=> | ||
| + | 27=> | ||
| + | 30=> | ||
| + | </ | ||
| + | |||
| + | == Runtime and performance observations == | ||
| + | |||
| + | The runtime on a Raspberry 3b+ with wabiForth for this check is around 24 minutes (and 5 sec to generate the report). The limiting factor is not the speed of the CPU, but the speed of the memory-bus and cache. This routine is the most cache-**in**efficient routine possible. In >99,99% of cases setting a bit in the array requires the reading and writing off a complete 64 byte cache line. Setting a bit 4294967296 times takes a while... The resulting memory bandwidth is < | ||