JDK-6464008 : Math and StrictMath random() Javadocs are inconsistent with code
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-08-25
  • Updated: 2013-08-22
  • Resolved: 2013-08-22
Related Reports
Duplicate :  
Description
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.

Comments
Duplicates JDK-6470700.
22-08-2013

EVALUATION Will investigate.
25-08-2006