MCPcopy Create free account
hub / github.com/DiUS/java-faker / decimalBetween

Method decimalBetween

src/main/java/com/github/javafaker/Number.java:94–110  ·  view source on GitHub ↗

@param min inclusive @param max exclusive @return

(long min, long max)

Source from the content-addressed store, hash-verified

92 * @return
93 */
94 private BigDecimal decimalBetween(long min, long max) {
95 if (min == max) {
96 return new BigDecimal(min);
97 }
98 final long trueMin = Math.min(min, max);
99 final long trueMax = Math.max(min, max);
100
101 final double range = (double) trueMax - (double) trueMin;
102
103 final double chunkCount = Math.sqrt(Math.abs(range));
104 final double chunkSize = chunkCount;
105 final long randomChunk = faker.random().nextLong((long) chunkCount);
106
107 final double chunkStart = trueMin + randomChunk * chunkSize;
108 final double adj = chunkSize * faker.random().nextDouble();
109 return new BigDecimal(chunkStart + adj);
110 }
111
112 public String digits(int count) {
113 final StringBuilder tmp = new StringBuilder();

Callers 5

randomDigitMethod · 0.95
randomDigitNotZeroMethod · 0.95
numberBetweenMethod · 0.95
randomNumberMethod · 0.95
randomDoubleMethod · 0.95

Calls 3

nextLongMethod · 0.80
nextDoubleMethod · 0.80
randomMethod · 0.45

Tested by

no test coverage detected