11package com .github .javafaker ;
22
33import java .math .BigDecimal ;
4+ import java .math .RoundingMode ;
45
56public class Number {
67 private final Faker faker ;
@@ -24,17 +25,17 @@ public int randomDigitNotZero() {
2425 }
2526
2627 /**
27- * @see Number#numberBetween(long, long)
28+ * @see Number#numberBetween(long, long)
2829 */
2930 public int numberBetween (int min , int max ) {
3031 if (min == max ) return min ;
3132
32- int value = decimalBetween (min ,max ).setScale (0 , BigDecimal . ROUND_HALF_DOWN ).intValue ();
33+ int value = decimalBetween (min ,max ).setScale (0 , RoundingMode . HALF_DOWN ).intValue ();
3334 return value == max ? value - 1 : value ;
3435 }
3536
3637 /**
37- * Return a number between <em>min</em> and <em>max</em>. If
38+ * Return a number between <em>min</em> and <em>max</em>. If
3839 * min == max, then min is returned. So numberBetween(2,2) will yield 2 even though
3940 * it doesn't make sense.
4041 *
@@ -44,10 +45,10 @@ public int numberBetween(int min, int max) {
4445 public long numberBetween (long min , long max ) {
4546 if (min == max ) return min ;
4647
47- long value = decimalBetween (min , max ).setScale (0 , BigDecimal . ROUND_HALF_DOWN ).longValue ();
48+ long value = decimalBetween (min , max ).setScale (0 , RoundingMode . HALF_DOWN ).longValue ();
4849 return value == max ? value - 1 : value ;
4950 }
50-
51+
5152 /**
5253 * @param numberOfDigits the number of digits the generated value should have
5354 * @param strict whether or not the generated value should have exactly <code>numberOfDigits</code>
@@ -82,7 +83,7 @@ public double randomDouble(int maxNumberOfDecimals, int min, int max) {
8283 */
8384 public double randomDouble (int maxNumberOfDecimals , long min , long max ) {
8485 return decimalBetween (min ,max )
85- .setScale (maxNumberOfDecimals , BigDecimal . ROUND_HALF_DOWN )
86+ .setScale (maxNumberOfDecimals , RoundingMode . HALF_DOWN )
8687 .doubleValue ();
8788 }
8889
@@ -99,13 +100,12 @@ private BigDecimal decimalBetween(long min, long max) {
99100 final long trueMax = Math .max (min , max );
100101
101102 final double range = (double ) trueMax - (double ) trueMin ;
102-
103+
103104 final double chunkCount = Math .sqrt (Math .abs (range ));
104- final double chunkSize = chunkCount ;
105105 final long randomChunk = faker .random ().nextLong ((long ) chunkCount );
106106
107- final double chunkStart = trueMin + randomChunk * chunkSize ;
108- final double adj = chunkSize * faker .random ().nextDouble ();
107+ final double chunkStart = trueMin + randomChunk * chunkCount ;
108+ final double adj = chunkCount * faker .random ().nextDouble ();
109109 return new BigDecimal (chunkStart + adj );
110110 }
111111
0 commit comments