aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/java/org/apache/poi/ss/formula/atp/RandBetween.java2
-rw-r--r--src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java17
2 files changed, 12 insertions, 7 deletions
diff --git a/src/java/org/apache/poi/ss/formula/atp/RandBetween.java b/src/java/org/apache/poi/ss/formula/atp/RandBetween.java
index 5eac08fe56..79f1c0acea 100644
--- a/src/java/org/apache/poi/ss/formula/atp/RandBetween.java
+++ b/src/java/org/apache/poi/ss/formula/atp/RandBetween.java
@@ -77,7 +77,7 @@ final class RandBetween implements FreeRefFunction{
top = bottom;
}
- return new NumberEval((bottom + (int)(Math.random() * ((top - bottom) + 1))));
+ return new NumberEval((bottom + (long)(Math.random() * ((top - bottom) + 1))));
}
diff --git a/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java b/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java
index 802b7d8b33..206d17016d 100644
--- a/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java
+++ b/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java
@@ -53,12 +53,6 @@ public class TestRandBetween extends TestCase {
formulaCell = row.createCell(2, CellType.FORMULA);
}
- @Override
- protected void tearDown() throws Exception {
- // TODO Auto-generated method stub
- super.tearDown();
- }
-
/**
* Check where values are the same
*/
@@ -74,6 +68,17 @@ public class TestRandBetween extends TestCase {
assertEquals(-1, formulaCell.getNumericCellValue(), 0);
}
+
+ public void testRandBetweenLargeLongs() {
+ for (int i = 0; i < 100; i++) {
+ evaluator.clearAllCachedResultValues();
+ formulaCell.setCellFormula("RANDBETWEEN(0,9999999999)");
+ evaluator.evaluateFormulaCell(formulaCell);
+ double value = formulaCell.getNumericCellValue();
+ assertTrue("rand is greater than or equal to lowerbound", value >= 0.0);
+ assertTrue("rand is less than or equal to upperbound", value <= 9999999999.0);
+ }
+ }
/**
* Check special case where rounded up bottom value is greater than