Repository: commons-rng
Updated Branches:
  refs/heads/master 22b5422cf -> d38b8e702


Loop rewrite (to avoid PMD warning).


Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/d38b8e70
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/d38b8e70
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/d38b8e70

Branch: refs/heads/master
Commit: d38b8e7029c384d27ff1dc9d4e0ec2a0284667c5
Parents: 22b5422
Author: Gilles <er...@apache.org>
Authored: Tue Oct 10 10:28:06 2017 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue Oct 10 10:28:06 2017 +0200

----------------------------------------------------------------------
 .../MarsagliaNormalizedGaussianSampler.java      | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rng/blob/d38b8e70/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/MarsagliaNormalizedGaussianSampler.java
----------------------------------------------------------------------
diff --git 
a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/MarsagliaNormalizedGaussianSampler.java
 
b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/MarsagliaNormalizedGaussianSampler.java
index 0ef6880..ef1f042 100644
--- 
a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/MarsagliaNormalizedGaussianSampler.java
+++ 
b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/MarsagliaNormalizedGaussianSampler.java
@@ -51,19 +51,18 @@ public class MarsagliaNormalizedGaussianSampler
                 final double y = 2 * nextDouble() - 1;
                 final double r2 = x * x + y * y;
 
-                if (r2 > 1 || r2 == 0) {
-                    // Pair is not within the unit circle: Generate another 
one.
-                    continue SAMPLE;
-                }
+                if (r2 <= 1 && r2 != 0) {
+                    // Pair (x, y) is within unit circle.
+                    final double alpha = Math.sqrt(-2 * Math.log(r2) / r2);
 
-                // Pair (x, y) is within unit circle.
-                final double alpha = Math.sqrt(-2 * Math.log(r2) / r2);
+                    // Keep second element of the pair for next invocation.
+                    nextGaussian = alpha * y;
 
-                // Keep second element of the pair for next invocation.
-                nextGaussian = alpha * y;
+                    // Return the first element of the generated pair.
+                    return alpha * x;
+                }
 
-                // Return the first element of the generated pair.
-                return alpha * x;
+                // Pair is not within the unit circle: Generate another one.
             }
         } else {
             // Use the second element of the pair (generated at the

Reply via email to