KISS (Zufallszahlengenerator)
KISS ist ein Zufallszahlengenerator, der von George Marsaglia entwickelt wurde.<ref name="jmasm" />
Sein Name rührt vom KISS-Prinzip her, der Generator ist eine Kombination aus drei einfachen Zufallszahlengeneratoren:
- Linearer Kongruenzgenerator,
- Xorshift und
- Lag-1 Multiply-with-carry.
Jeder dieser Generatoren für sich alleine besteht praktisch keine Tests auf Zufälligkeit. Die Kombination in Form des KISS-Generators besteht jedoch alle statistischen Tests aus dem BigCrush-Test der TestU01-Bibliothek.<ref name="testu01" />
Eigenschaften
- Periodenlänge:
- größer als 2124 ≈ 2,12 · 1037 (32-Bit-Version)
- größer als 2247 ≈ 2,26 · 1074 (64-Bit-Version)<ref>https://www.thecodingforums.com/threads/64-bit-kiss-rngs.673657/</ref>
- kleiner Zustandsvektor: 4 Werte zu je 32 bzw. 64 Bit
- benutzt nur einfache Rechenoperationen: Shift, Addition, Multiplikation
- einfache Implementierung
Implementierung in C
| 32 Bit | 64 Bit |
|---|---|
|
<syntaxhighlight lang="C">
// interner Zustand static uint32_t x = 123456789; // seed beliebig, static uint32_t y = 362436000; // aber y != 0 und static uint32_t z = 521288629; // z,c nicht beide 0 static uint32_t c = 7654321; uint32_t KISS() { uint64_t t; // Linearer Kongruenzgenerator x = 69069 * x + 12345; // Xorshift y ^= y << 13; y ^= y >> 17; y ^= y << 5; // Multiply-with-carry t = (uint64_t)698769069 * z + c; c = t >> 32; z = (uint32_t) t; return x + y + z; } </syntaxhighlight> |
<syntaxhighlight lang="C">
// interner Zustand static uint64_t x = 1066149217761810ULL; static uint64_t y = 362436362436362436ULL; static uint64_t z = 1234567890987654321ULL; static uint64_t c = 123456123456123456ULL; uint64_t KISS64() { uint64_t t; // Linearer Kongruenzgenerator x = 6906969069ULL * x + 1234567; // Xorshift y ^= y << 13; y ^= y >> 17; y ^= y << 43; // Multiply-with-carry t = (z << 58) + c; c = z >> 6; z += t; c += z < t; return x + y + z; } </syntaxhighlight> |
Siehe auch
Einzelnachweise
<references> <ref name="testu01"> Pierre L’Ecuyer, Richard Simard: TestU01: A C library for empirical testing of random number generators. In: ACM Transactions on Mathematical Software, Volume 33, Issue 4, August 2007 </ref> <ref name="jmasm"> Journal Of Modern Applied Statistical Methods, May, 2003, Vol. 2 (PDF; 9,5 MB) </ref> </references>