Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. // Kirby Super Star: RNG Simulator POC
  2.  
  3. #include <stdio.h>
  4. #include <stdint.h>
  5.  
  6. static uint16_t seed = 0x7777;
  7.  
  8. uint8_t random(uint8_t limit) {
  9. for (int i = 0; i < 11; i++) {
  10. uint16_t bit = ~(seed ^ (seed >> 1) ^ (seed >> 15)) & 1;
  11. seed = (seed << 1) | bit;
  12. }
  13.  
  14. uint8_t value = seed & 0xff;
  15. if (limit != 0) {
  16. value = (value * limit) >> 8;
  17. }
  18. return value;
  19. }
  20.  
  21. int main(void)
  22. {
  23. printf("0x%04x\n", seed);
  24. for (int tick = 0; tick < 10; tick++) {
  25. random(0);
  26. printf("0x%04x\n", seed);
  27. }
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement