Advertisement
mgostih

Super Mario 64 RNG Function

Nov 6th, 2016
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. unsigned short RNG64(unsigned short input){
  3.     unsigned short S0 = (input & 0xFF) << 8;
  4.     S0 ^= input;
  5.    
  6.     input = (S0 << 8) + (S0 >> 8);
  7.     S0 = input ^ ((S0 & 0xFF) << 1);
  8.  
  9.     unsigned short S1 = (0xFF80 ^ (S0 >> 1));
  10.    
  11.     return S0 & 1 ? S1 ^ 0x8180 : S1 ^ 0x1FF4;
  12. }
  13. unsigned short RNGWrapper(){
  14.     static unsigned short StoredInput=0;
  15.     StoredInput = RNG64(StoredInput);
  16.     return StoredInput;
  17.    
  18. }
  19. int main(){
  20.     for (int i = 0; i < 50; i++){
  21.         std::cout << RNGWrapper() << std::endl;
  22.     }
  23.     system("PAUSE>NUL");
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement