Skip to content

Instantly share code, notes, and snippets.

@gocha
Created August 7, 2019 15:20
Show Gist options
  • Save gocha/646f70207e3684fef7678a3b291270c3 to your computer and use it in GitHub Desktop.
Save gocha/646f70207e3684fef7678a3b291270c3 to your computer and use it in GitHub Desktop.
Kirby Super Star: RNG Simulator POC (Hoshi no Kirby Super Deluxe)
// Kirby Super Star: RNG Simulator POC
#include <stdio.h>
#include <stdint.h>
static uint16_t seed = 0x7777;
uint8_t random(uint8_t limit) {
for (int i = 0; i < 11; i++) {
uint16_t bit = ~(seed ^ (seed >> 1) ^ (seed >> 15)) & 1;
seed = (seed << 1) | bit;
}
uint8_t value = seed & 0xff;
if (limit != 0) {
value = (value * limit) >> 8;
}
return value;
}
int main(void)
{
printf("0x%04x\n", seed);
for (int tick = 0; tick < 10; tick++) {
random(0);
printf("0x%04x\n", seed);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment