Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.
/ jdk17 Public archive

Commit 72db09b

Browse files
author
Jim Laskey
committed
8266313: (JEP-356) - RandomGenerator spec implementation requirements tightly coupled to JDK internal classes
Reviewed-by: rriggs
1 parent 3bbd233 commit 72db09b

File tree

2 files changed

+50
-31
lines changed

2 files changed

+50
-31
lines changed

Diff for: src/java.base/share/classes/java/util/random/RandomGenerator.java

+49-30
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,10 @@ default float nextFloat() {
516516
* @throws IllegalArgumentException if {@code bound} is not
517517
* both positive and finite
518518
*
519-
* @implSpec The default implementation simply calls
520-
* {@link RandomSupport#checkBound checkBound}(bound) and then
521-
* {@link RandomSupport#boundedNextFloat boundedNextFloat}(this, bound).
519+
* @implSpec The default implementation checks that {@code bound} is a
520+
* positive finite float. Then invokes {@code nextFloat()}, scaling
521+
* the result so that the final result lies between {@code 0.0f} (inclusive)
522+
* and {@code bound} (exclusive).
522523
*/
523524
default float nextFloat(float bound) {
524525
RandomSupport.checkBound(bound);
@@ -540,9 +541,11 @@ default float nextFloat(float bound) {
540541
* or {@code bound} is not finite, or {@code origin}
541542
* is greater than or equal to {@code bound}
542543
*
543-
* @implSpec The default implementation simply calls
544-
* {@link RandomSupport#checkBound checkBound}(bound) and then
545-
* {@link RandomSupport#boundedNextFloat boundedNextFloat}(this, bound).
544+
* @implSpec The default implementation checks that {@code origin} and
545+
* {@code bound} are positive finite floats. Then invokes
546+
* {@code nextFloat()}, scaling and translating the result so that the final
547+
* result lies between {@code origin} (inclusive) and {@code bound}
548+
* (exclusive).
546549
*/
547550
default float nextFloat(float origin, float bound) {
548551
RandomSupport.checkRange(origin, bound);
@@ -577,9 +580,10 @@ default double nextDouble() {
577580
* @throws IllegalArgumentException if {@code bound} is not
578581
* both positive and finite
579582
*
580-
* @implSpec The default implementation simply calls
581-
* {@link RandomSupport#checkBound checkBound}(bound) and then
582-
* {@link RandomSupport#boundedNextDouble boundedNextDouble}(this, bound).
583+
* @implSpec The default implementation checks that {@code bound} is a
584+
* positive finite double. Then invokes {@code nextDouble()}, scaling
585+
* the result so that the final result lies between {@code 0.0} (inclusive)
586+
* and {@code bound} (exclusive).
583587
*/
584588
default double nextDouble(double bound) {
585589
RandomSupport.checkBound(bound);
@@ -601,9 +605,11 @@ default double nextDouble(double bound) {
601605
* or {@code bound} is not finite, or {@code origin}
602606
* is greater than or equal to {@code bound}
603607
*
604-
* @implSpec The default implementation simply calls
605-
* {@link RandomSupport#checkBound checkBound}(bound) and then
606-
* {@link RandomSupport#boundedNextDouble boundedNextDouble}(this, bound).
608+
* @implSpec The default implementation checks that {@code origin} and
609+
* {@code bound} are positive finite doubles. Then calls
610+
* {@code nextDouble()}, scaling and translating the result so that the final
611+
* result lies between {@code origin} (inclusive) and {@code bound}
612+
* (exclusive).
607613
*/
608614
default double nextDouble(double origin, double bound) {
609615
RandomSupport.checkRange(origin, bound);
@@ -627,16 +633,20 @@ default int nextInt() {
627633
* Returns a pseudorandomly chosen {@code int} value between zero
628634
* (inclusive) and the specified bound (exclusive).
629635
*
630-
* @param bound the upper bound (exclusive) for the returned value. Must be positive.
636+
* @param bound the upper bound (exclusive) for the returned value.
637+
* Must be positive.
631638
*
632639
* @return a pseudorandomly chosen {@code int} value between
633640
* zero (inclusive) and the bound (exclusive)
634641
*
635642
* @throws IllegalArgumentException if {@code bound} is not positive
636643
*
637-
* @implSpec The default implementation simply calls
638-
* {@link RandomSupport#checkBound checkBound}(bound) and then
639-
* {@link RandomSupport#boundedNextInt boundedNextInt}(this, bound).
644+
* @implSpec The default implementation checks that {@code bound} is a
645+
* positive {@code int}. Then invokes {@code nextInt()}, limiting the result
646+
* to be greater than or equal zero and less than {@code bound}. If {@code bound}
647+
* is a power of two then limiting is a simple masking operation. Otherwise,
648+
* the result is re-calculated by invoking {@code nextInt()} until the
649+
* result is greater than or equal zero and less than {@code bound}.
640650
*/
641651
default int nextInt(int bound) {
642652
RandomSupport.checkBound(bound);
@@ -657,9 +667,13 @@ default int nextInt(int bound) {
657667
* @throws IllegalArgumentException if {@code origin} is greater than
658668
* or equal to {@code bound}
659669
*
660-
* @implSpec The default implementation simply calls
661-
* {@link RandomSupport#checkBound(long) checkBound}(bound) and then
662-
* {@link RandomSupport#boundedNextInt(RandomGenerator, int) boundedNextInt}(this, bound).
670+
* @implSpec The default implementation checks that {@code origin} and
671+
* {@code bound} are positive {@code ints}. Then invokes {@code nextInt()},
672+
* limiting the result to be greater that or equal {@code origin} and less
673+
* than {@code bound}. If {@code bound} is a power of two then limiting is a
674+
* simple masking operation. Otherwise, the result is re-calculated by
675+
* invoking {@code nextInt()} until the result is greater than or equal
676+
* {@code origin} and less than {@code bound}.
663677
*/
664678
default int nextInt(int origin, int bound) {
665679
RandomSupport.checkRange(origin, bound);
@@ -678,16 +692,21 @@ default int nextInt(int origin, int bound) {
678692
* Returns a pseudorandomly chosen {@code long} value between zero
679693
* (inclusive) and the specified bound (exclusive).
680694
*
681-
* @param bound the upper bound (exclusive) for the returned value. Must be positive.
695+
* @param bound the upper bound (exclusive) for the returned value.
696+
* Must be positive.
682697
*
683698
* @return a pseudorandomly chosen {@code long} value between
684699
* zero (inclusive) and the bound (exclusive)
685700
*
686701
* @throws IllegalArgumentException if {@code bound} is not positive
687702
*
688-
* @implSpec The default implementation simply calls
689-
* {@link RandomSupport#checkBound checkBound}(bound) and then
690-
* {@link RandomSupport#boundedNextLong boundedNextLong}(this, bound).
703+
* @implSpec The default implementation checks that {@code bound} is a
704+
* positive {@code long}. Then invokes {@code nextLong()}, limiting the
705+
* result to be greater than or equal zero and less than {@code bound}. If
706+
* {@code bound} is a power of two then limiting is a simple masking
707+
* operation. Otherwise, the result is re-calculated by invoking
708+
* {@code nextLong()} until the result is greater than or equal zero and
709+
* less than {@code bound}.
691710
*/
692711
default long nextLong(long bound) {
693712
RandomSupport.checkBound(bound);
@@ -708,9 +727,13 @@ default long nextLong(long bound) {
708727
* @throws IllegalArgumentException if {@code origin} is greater than
709728
* or equal to {@code bound}
710729
*
711-
* @implSpec The default implementation simply calls
712-
* {@link RandomSupport#checkBound checkBound}(bound) and then
713-
* {@link RandomSupport#boundedNextLong boundedNextLong}(this, bound).
730+
* @implSpec The default implementation checks that {@code origin} and
731+
* {@code bound} are positive {@code longs}. Then invokes {@code nextLong()},
732+
* limiting the result to be greater than or equal {@code origin} and less
733+
* than {@code bound}. If {@code bound} is a power of two then limiting is a
734+
* simple masking operation. Otherwise, the result is re-calculated by
735+
* invoking {@code nextLong()} until the result is greater than or equal
736+
* {@code origin} and less than {@code bound}.
714737
*/
715738
default long nextLong(long origin, long bound) {
716739
RandomSupport.checkRange(origin, bound);
@@ -892,10 +915,6 @@ interface SplittableGenerator extends StreamableGenerator {
892915
* Returns an instance of {@link SplittableGenerator} that utilizes the
893916
* {@code name} <a href="package-summary.html#algorithms">algorithm</a>.
894917
*
895-
* @implNote Availability is determined by RandomGeneratorFactory using the
896-
* service provider API to locate implementations of the RandomGenerator
897-
* interface and filtering on the SplittableGenerator interface.
898-
*
899918
* @param name Name of random number generator
900919
* <a href="package-summary.html#algorithms">algorithm</a>
901920
*

Diff for: src/java.base/share/classes/java/util/random/RandomGeneratorFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ public static RandomGeneratorFactory<RandomGenerator> getDefault() {
374374
/**
375375
* Returns a non-empty stream of available {@link RandomGeneratorFactory RandomGeneratorFactory(s)}.
376376
*
377-
* RandomGenerators that are marked as deprecated or are not properly configured are not included in the result.
377+
* RandomGenerators that are marked as deprecated are not included in the result.
378378
*
379379
* @implSpec Availability is determined by RandomGeneratorFactory using the service provider API
380380
* to locate implementations of the RandomGenerator interface.

0 commit comments

Comments
 (0)