Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement