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

(spec) Random.nextLong(), nextDouble() cannot generate all possible values, as specified

XMLWordPrintable

    • b61
    • x86
    • windows_xp

      Name: rmT116609 Date: 03/05/2003


      DESCRIPTION OF THE PROBLEM :
      Documentation of nextDouble() in java.util.Random contains
      the sentence:

      "All 2^53 possible float values of the form m x 2^-53 ,
      where m is a positive integer less than 2^53, are produced
      with (approximately) equal probability."

      I believe this statement is incorrect, and also contains a
      typo.

      As Random uses only a 48-bit seed, the number of different
      values of a given type that may be produced is clearly
      bounded by 2^48. Hence only 2^48 different doubles can be
      returned, which is only 1/32 of the claimed range.

      The "approximately" does not (IMHO) absorb the error, as
      {2^-48, 0, 0, 0, ..... 0, 0} is nothing like {2^-53, 2^-53,
      2^-53, 2^-53, .... 2^-53, 2^-53}.

      Also, the word "float" is used where "double" is probably
      intended.

      REPRODUCIBILITY :
      This bug can be reproduced always.
      (Review ID: 180209)
      ======================================================================

            martin Martin Buchholz
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: