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

ThreadLocalRandom bug - overridden setSeed(long) method is not invoked for java.util.Random(long)

XMLWordPrintable

    • b94
    • 7
    • b100
    • generic
    • generic
    • Not verified

      The constructor of the java.util.Random class, which creates a new random number generator using a single {@code long} seed, doesn't calls setSeed(seed) method more.
      In brief, spec should be clarified here. Actual spec says that Random(seed) is equivalent to

      Random rnd = new Random();
      rnd.setSeed(seed);

      But current implementation does the same as the code above, but does not call rnd.setSeed(seed). It is not obvious at all - does it still "equivalent" or not that clearly demonstrated by corresponding JCK test.
      More precise the Random(seed) is not equivalent to

      Random rnd = new Random();
      rnd.setSeed(seed);

      As described in the my comments the haveNextNextGaussian variable will not be cleaned if the instance of Random created with Random(seed) constructor.

            dholmes David Holmes
            afomin Alexander Fomin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: