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 2019/02/26 13:46:40 UTC
[commons-rng] 01/02: DiscreteProbabilityCollectionSampler: Fix
index check from binarySearch.
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 89ee371d557fc339cc76a91540e870b7e2de4750
Author: aherbert <ah...@apache.org>
AuthorDate: Tue Feb 26 13:14:36 2019 +0000
DiscreteProbabilityCollectionSampler: Fix index check from binarySearch.
The index cannot be negative after the conversion. -Integer.MIN_VALUE -1
= Integer.MAX_VALUE due to underflow.
---
.../commons/rng/sampling/DiscreteProbabilityCollectionSampler.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/DiscreteProbabilityCollectionSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/DiscreteProbabilityCollectionSampler.java
index 8c77da0..f85ff14 100644
--- a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/DiscreteProbabilityCollectionSampler.java
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/DiscreteProbabilityCollectionSampler.java
@@ -135,8 +135,7 @@ public class DiscreteProbabilityCollectionSampler<T> {
index = -index - 1;
}
- if (index >= 0 &&
- index < cumulativeProbabilities.length &&
+ if (index < cumulativeProbabilities.length &&
rand < cumulativeProbabilities[index]) {
return items.get(index);
}