Created
May 5, 2021 18:31
-
-
Save stevenjohnstone/52f17d8fed87c476a33914bcb981f0b9 to your computer and use it in GitHub Desktop.
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
// https://roadrunnerwmc.github.io/blog/2020/05/08/nsmb-rng.html takes about 10 seconds to find | |
// a fixed point for the random number generator | |
#include <assert.h> | |
#include <stdio.h> | |
#include <stdint.h> | |
uint32_t rand_nsmb(uint32_t *state) { | |
uint64_t value = (uint64_t)(*state) * 1664525 + 1013904223; | |
return *state = value + (value >> 32); | |
} | |
int main(int argc, const char **argv) { | |
uint32_t candidate = ~0; | |
do { | |
uint32_t state = candidate; | |
if (rand_nsmb(&state) == candidate) { | |
printf("found 0x%08x\n", candidate); | |
return 0; | |
} | |
} while (candidate--); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment