Skip to content

Commit

Permalink
Ensure defaults for float/double generation result in random values
Browse files Browse the repository at this point in the history
Also ensures generating BigIntegers with a default range can contain
some nulls.
  • Loading branch information
niloc132 committed Oct 27, 2023
1 parent 0b289ba commit c62aa2e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public BigIntegerGenerator() {

public BigIntegerGenerator(double nullFraction) {
this(BigInteger.valueOf(Long.MIN_VALUE).multiply(BigInteger.valueOf(2)),
BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2)), 0);
BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2)), nullFraction);
}

public BigIntegerGenerator(BigInteger from, BigInteger to) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private double generateDouble(Random random) {
return Double.POSITIVE_INFINITY;
}
}
return from + (random.nextDouble() * to - from);
return (from / 2 + (random.nextDouble() * (to / 2 - from / 2))) * 2;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private float generateFloat(Random random) {
return Float.POSITIVE_INFINITY;
}
}
return from + (random.nextFloat() * to - from);
return (from / 2 + (random.nextFloat() * (to / 2 - from / 2))) * 2;
}

@Override
Expand Down

0 comments on commit c62aa2e

Please sign in to comment.