Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- initialHeight = 26;
- launchTntCount = 7;
- generateDetectorCircle();
- long[] lut = new long[detectors.size()];
- for (int i = 0; i < lut.length; i++)
- lut[i] = getUpperSeedBound(i);
- final long a = 0x97be9f880aa9L;
- final long b = 0xeac471130bcaL;
- long[] bvec = {0xc8fbaf16b114L, 0xc2a36898b9feL, 0x13e60619c078L, 0xe7244157cb02L, 0x3771906241cL, 0x47d6c669fa46L, 0L};
- final long[] m6 = {0xff7392795dd6L, 0x1184f9b300L, 0xff79d1d659aeL, 0xff62f08153d5L, 0xfe64fe5e8622L, 0x24beb7ecc11L, 0x30c38f7adcL};
- final long[][] mm1 = {
- {-26, -81, -16, 50, 14, 22, -76},
- {-117, 4, -42, -45, -20, -61, -32},
- {3, 79, 1, 92, 5, 26, 8},
- {18, 28, 48, 53, -92, -33, -33},
- {43, 63, -68, -10, 33, 18, -57},
- {-21, -6, 91, -19, 56, 51, -12},
- {-44, 25, -6, -1, -44, 65, 34}
- };
- bvec = matmult(mm1, bvec);
- for (int i = 0; i < 100; i++) {
- Random rand = new Random();
- int[] detectorArray = new int[7];
- for (int j = 0; j < 7; j++) {
- detectorArray[j] = getDetectorOutput(rand.nextDouble());
- for (int k = 0; k < 2696; k++)
- rand.nextDouble();
- }
- long[] penultimateVector = new long[7];
- for (int j = 0; j < 7; j++) {
- long[] v = new long[7];
- for (int k = 0; k < 7; k++) {
- int detectorId = detectorArray[k];
- if ((mm1[j][k] & 0x800000000000L) != 0) { // if it's negative mod 2^48
- detectorId--;
- if (detectorId < 0)
- detectorId += detectors.size();
- v[k] = lut[detectorId] & ~((1L << (48 - 26)) - 1);
- } else {
- v[k] = lut[detectorId];
- }
- }
- BigInteger val = dotBig(mm1[j], v);
- val = val.subtract(BigInteger.valueOf(bvec[j]));
- val = val.shiftRight(48);
- penultimateVector[j] = val.longValue();
- }
- long seed = dot(m6, penultimateVector) & 0xffffffffffffL;
- System.out.println("Expected: " + getSeed(rand) + ", actual: " + seed);
- }
- }
- private static BigInteger dotBig(long[] a, long[] b) {
- BigInteger result = BigInteger.ZERO;
- for (int i = 0; i < a.length; i++) {
- result = result.add(BigInteger.valueOf(a[i] & 0xffffffffffffL).multiply(BigInteger.valueOf(b[i] & 0xffffffffffffL)));
- }
- return result;
- }
- private static long dot(long[] a, long[] b) {
- long result = 0;
- for (int i = 0; i < a.length; i++)
- result += a[i] * b[i];
- return result;
- }
- private static long[] matmult(long[][] mat, long[] vec) {
- long[] result = new long[mat.length];
- for (int i = 0; i < mat.length; i++)
- result[i] = dot(mat[i], vec);
- return result;
- }
- private static long getSeed(Random rand) {
- try {
- Field field = Random.class.getDeclaredField("seed");
- field.setAccessible(true);
- return ((AtomicLong) field.get(rand)).get();
- } catch (ReflectiveOperationException e) {
- e.printStackTrace();
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement