Advertisement
Dotsarecool

SMW RNG Simulation

Jun 21st, 2017
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1.  
  2. public class SMWRNG {
  3.    
  4.     static byte[] rng;
  5.  
  6.     public static void main(String[] args) {
  7.         rng = new byte[4];
  8.        
  9.         for (int i = 0; i <= 27776; i++) {
  10.             simulateRNG();
  11.             print(i);
  12.         }
  13.     }
  14.    
  15.     public static byte simulateRNG() {
  16.         byte y = 1;
  17.         tickRNG(y);
  18.         y--;
  19.         tickRNG(y);
  20.         return rng[2];
  21.     }
  22.    
  23.     public static void tickRNG(byte y) {
  24.         rng[0] = (byte) (5 * rng[0] + 1);
  25.  
  26.         boolean c = (rng[1] & 0x80) != 0;
  27.         boolean z = (rng[1] & 0x10) != 0;
  28.        
  29.         rng[1] = (byte) (2 * rng[1]);
  30.        
  31.         if (c == z) {
  32.             rng[1]++;
  33.         }
  34.        
  35.         rng[2+y] = (byte) (rng[0] ^ rng[1]);
  36.     }
  37.    
  38.     public static void print(int i) {
  39.         System.out.printf("%5d) S: %s, T: %s, J: %s, K: %s%n", i, b2s(rng[0]), b2s(rng[1]), b2s(rng[2]), b2s(rng[3]));
  40.     }
  41.    
  42.     public static String b2s(byte b) {
  43.         return String.format("%2x", b).toUpperCase().replace(' ', '0');
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement