Code:
#include <stdint.h>
// interner Zustand
static uint32_t x = 123456789; // <- beliebige seed != 0
static uint32_t y = 362436000;
static uint32_t z = 521288629;
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 = 698769069ULL * z + c;
c = t >> 32;
z = (uint32_t) t;
return x + y + z;
}
Das ist dein Zufallszahlengeneratur.
static uint32_t x = 123456789; // <- beliebige seed != 0
Das ist dein seed. Der "Samen" des Zufalls. Ist dieser Wert immer gleich, kommt immer dieselbe Reihe an Zahlen raus. Ergo, addiere einfach eine Zeit aus einem Timer beim Start des Spieles drauf... aber nur einmalig.
Lesezeichen