Advertisement
Earthcomputer

Untitled

Mar 27th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.03 KB | None | 0 0
  1.     public static void main(String[] args) {
  2.         initialHeight = 26;
  3.         launchTntCount = 7;
  4.         generateDetectorCircle();
  5.         long[] lut = new long[detectors.size()];
  6.         for (int i = 0; i < lut.length; i++)
  7.             lut[i] = getUpperSeedBound(i);
  8.  
  9.         final long a = 0x97be9f880aa9L;
  10.         final long b = 0xeac471130bcaL;
  11.         long[] bvec = {0xc8fbaf16b114L, 0xc2a36898b9feL, 0x13e60619c078L, 0xe7244157cb02L, 0x3771906241cL, 0x47d6c669fa46L, 0L};
  12.         final long[] m6 = {0xff7392795dd6L, 0x1184f9b300L, 0xff79d1d659aeL, 0xff62f08153d5L, 0xfe64fe5e8622L, 0x24beb7ecc11L, 0x30c38f7adcL};
  13.         final long[][] mm1 = {
  14.                 {-26, -81, -16, 50, 14, 22, -76},
  15.                 {-117, 4, -42, -45, -20, -61, -32},
  16.                 {3, 79, 1, 92, 5, 26, 8},
  17.                 {18, 28, 48, 53, -92, -33, -33},
  18.                 {43, 63, -68, -10, 33, 18, -57},
  19.                 {-21, -6, 91, -19, 56, 51, -12},
  20.                 {-44, 25, -6, -1, -44, 65, 34}
  21.         };
  22.         bvec = matmult(mm1, bvec);
  23.  
  24.         for (int i = 0; i < 100; i++) {
  25.             Random rand = new Random();
  26.             int[] detectorArray = new int[7];
  27.             for (int j = 0; j < 7; j++) {
  28.                 detectorArray[j] = getDetectorOutput(rand.nextDouble());
  29.                 for (int k = 0; k < 2696; k++)
  30.                     rand.nextDouble();
  31.             }
  32.  
  33.             long[] penultimateVector = new long[7];
  34.             for (int j = 0; j < 7; j++) {
  35.                 long[] v = new long[7];
  36.                 for (int k = 0; k < 7; k++) {
  37.                     int detectorId = detectorArray[k];
  38.                     if ((mm1[j][k] & 0x800000000000L) != 0) { // if it's negative mod 2^48
  39.                         detectorId--;
  40.                         if (detectorId < 0)
  41.                             detectorId += detectors.size();
  42.                     }
  43.                     v[k] = lut[detectorId];
  44.                 }
  45.                 long val = dot(mm1[j], v);
  46.                 val -= bvec[j];
  47.                 val >>>= 1L << 48;
  48.                 penultimateVector[j] = val;
  49.             }
  50.  
  51.             long seed = dot(m6, penultimateVector) & 0xffffffffffffL;
  52.             System.out.println("Expected: " + getSeed(rand) + ", actual: " + seed);
  53.         }
  54.     }
  55.  
  56.     private static long dot(long[] a, long[] b) {
  57.         long result = 0;
  58.         for (int i = 0; i < a.length; i++)
  59.             result += a[i] * b[i];
  60.         return result;
  61.     }
  62.  
  63.     private static long[] matmult(long[][] mat, long[] vec) {
  64.         long[] result = new long[mat.length];
  65.         for (int i = 0; i < mat.length; i++)
  66.             result[i] = dot(mat[i], vec);
  67.         return result;
  68.     }
  69.  
  70.     private static long getSeed(Random rand) {
  71.         try {
  72.             Field field = Random.class.getDeclaredField("seed");
  73.             field.setAccessible(true);
  74.             return ((AtomicLong) field.get(rand)).get();
  75.         } catch (ReflectiveOperationException e) {
  76.             e.printStackTrace();
  77.             return 0;
  78.         }
  79.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement