Skip to content
This repository has been archived by the owner on Feb 25, 2024. It is now read-only.

Commit

Permalink
implement Java 17 j.u.r.RandomGenerator#nextExponential()
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-zobel committed Sep 18, 2021
1 parent aa1d002 commit a36de70
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/main/java/java8/util/SplittableRandom.java
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,22 @@ public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound)
false);
}

/**
* Returns a nonnegative {@code double} value pseudorandomly chosen from
* an exponential distribution whose mean is 1.
*
* @return a nonnegative {@code double} value pseudorandomly chosen from an
* exponential distribution
* @since 17
*/
public double nextExponential() {
double u;
do {
u = nextDouble();
} while (u == 0.0 || u == 1.0);
return -Math.log(u);
}

/**
* Return true if the implementation of RandomGenerator (algorithm) has been
* marked for deprecation.
Expand All @@ -858,7 +874,6 @@ public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound)
*
* @return true if the implementation of RandomGenerator (algorithm) has been
* marked for deprecation
*
* @since 17
*/
public boolean isDeprecated() {
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/java8/util/concurrent/ThreadLocalRandom.java
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,22 @@ public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound)
false);
}

/**
* Returns a nonnegative {@code double} value pseudorandomly chosen from
* an exponential distribution whose mean is 1.
*
* @return a nonnegative {@code double} value pseudorandomly chosen from an
* exponential distribution
* @since 17
*/
public double nextExponential() {
double u;
do {
u = nextDouble();
} while (u == 0.0 || u == 1.0);
return -Math.log(u);
}

/**
* Return true if the implementation of RandomGenerator (algorithm) has been
* marked for deprecation.
Expand All @@ -745,7 +761,6 @@ public DoubleStream doubles(double randomNumberOrigin, double randomNumberBound)
*
* @return true if the implementation of RandomGenerator (algorithm) has been
* marked for deprecation
*
* @since 17
*/
public boolean isDeprecated() {
Expand Down

0 comments on commit a36de70

Please sign in to comment.