Zum Inhalt springen

KISS (Zufallszahlengenerator)

aus Wikipedia, der freien Enzyklopädie

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:

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:
  • 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">

  1. include <stdint.h>

// 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">

  1. include <stdint.h>

// 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>