Last active
September 9, 2024 10:45
-
-
Save kspalaiologos/f890df61be35f65b1f80283f6cb3b92a to your computer and use it in GitHub Desktop.
Compact Cyclic Generator - a fast non-cryptographic random number generator based on polynomial codes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Public Domain. | |
#include <stdint.h> | |
#include <stdio.h> | |
uint32_t s, b; | |
void ccg_seed(uint32_t seed) { | |
s = (b = seed ^ 0xAAAAAAAA) | 1; | |
} | |
uint32_t ccg_next() { | |
uint32_t b = s >> 31; | |
s <<= 1, s ^= b * 0xEDB88320; | |
return s ^ b; | |
} | |
int main() { | |
ccg_seed(0x82F63B78); | |
for (;;) { | |
uint32_t x = ccg_next(); | |
fwrite(&x, 4, 1, stdout); | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment