You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2021/08/05 16:45:56 UTC
[commons-rng] 05/21: Compute result after the loop
This is an automated email from the ASF dual-hosted git repository.
aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git
commit 5d8a92731dc1d80354da840375ab7c86a92eeec5
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Thu Aug 5 13:50:59 2021 +0100
Compute result after the loop
---
.../commons/rng/examples/quadrature/MonteCarloIntegration.java | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/commons-rng-examples/examples-quadrature/src/main/java/org/apache/commons/rng/examples/quadrature/MonteCarloIntegration.java b/commons-rng-examples/examples-quadrature/src/main/java/org/apache/commons/rng/examples/quadrature/MonteCarloIntegration.java
index ff775d3..df21688 100644
--- a/commons-rng-examples/examples-quadrature/src/main/java/org/apache/commons/rng/examples/quadrature/MonteCarloIntegration.java
+++ b/commons-rng-examples/examples-quadrature/src/main/java/org/apache/commons/rng/examples/quadrature/MonteCarloIntegration.java
@@ -48,19 +48,14 @@ public abstract class MonteCarloIntegration {
* @return the integral.
*/
public double integrate(long n) {
- double result = 0;
long inside = 0;
- long total = 0;
- while (total < n) {
+ for (long i = 0; i < n; i++) {
if (isInside(generateU01())) {
++inside;
}
-
- ++total;
- result = inside / (double) total;
}
- return result;
+ return inside / (double) n;
}
/**