Uploaded image for project: 'Commons RNG'
  1. Commons RNG
  2. RNG-81

NumberFactory to evenly sample all representable rationals between 0 and 1

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Implemented
    • 1.3
    • 1.3
    • core
    • None

    Description

      Change the number factory methods for nextFloat and nextDouble

      Currently the methods use:

      • 23-bits of state from an int to create a float
      • 52-bits of state from a long to create a double

      This method produces output floating point numbers with the final bit of the mantissa set to 0. The methods can be changed to use 24-bits and 53-bits of state respectively.

      This will match the implementation in java.util.SplittableRandom.

      Benchmarking has shown no noticeable difference in speed.

      Note that this change modifies the output float to evenly sample all k/2^-24 dyadic rationals and the double to evenly sample all k/2^-53 dyadic rationals, i.e. the maximum number representable between 0 (inclusive) and 1.0 (exclusive).

       

      Attachments

        Issue Links

          Activity

            People

              aherbert Alex Herbert
              aherbert Alex Herbert
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 10m
                  1h 10m