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

Math and StrictMath random() Javadocs are inconsistent with code

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • core-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.5.0_07"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)
      Java HotSpot(TM) Client VM (build 1.5.0_07-b03, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      The Math.random() and StrictMath.random() Javadoc states, "This method is properly synchronized to allow correct use by more than one thread. However, if many threads need to generate pseudorandom numbers at a great rate, it may reduce contention for each thread to have its own pseudorandom number generator."

      However, no synchronisation is evident in the Math class, or the underlying Random.nextDouble() and Random.next() implementations apart from the creation of the Random object itself. This could possibly be dangerous is a multi-threaded application is dependant on the stated behaviour to give a consistent and reproducable set of random numbers.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Either the Javadoc, or the underlying code need to be changed to be consistent.
      ACTUAL -
      Javadoc and underlying code are inconsistent.

      REPRODUCIBILITY :
      This bug can be reproduced always.

            bpb Brian Burkhalter
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: