Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8074460

Always print seeds used in [Splittable]Random instances in java.math tests

XMLWordPrintable

    • b55

        This is what I found:

        1. Seed is constant hence redundant to print on failure
        ./BigInteger/ModPow.java
        ./BigInteger/PrimitiveConversionTests.java

        2. Seed is printed on failure
        ./BigDecimal/StringConstructor.java

        3. Seed is not printed on failure
        3.1 Uses parameterless Random()
        ./BigInteger/BigIntegerTest.java
        ./BigInteger/ModPow65537.java
        ./BigInteger/SymmetricRangeTests.java

        Fixing these tests to print the seed is not a problem as a construct such as

            private static int seed = new Random().nextInt();
            private static Random rnd = new Random(seed);

        which is used in the StringConstructor test could be applied. The Random instance actually used is ‘rnd’ and while its seed itself is random it is known and may be printed.

        A slight change might actually be better:

            private static Random rnd;
            private static long seed;

            static {
                rnd = new Random();
                seed = rnd.nextLong();
                rnd.setSeed(seed);
            }

        3.2 Uses parameterless SplittableRandom()
        ./BigInteger/PrimeTest.java

        Something similar to what is currently done in StringConstructor could be done here as well to fix the problem. SplittableRandom does not have a setSeed() method so the other approach is infeasible.

        Note that there is no way to retrieve from an instance of either class the seed that was used by the parameterless constructor.

              bpb Brian Burkhalter
              bpb Brian Burkhalter
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: