To generrate BigDecimal between 0 to defined range use following code:
private BigDecimal randomNo(int range) {
BigDecimal rangeInBD = new BigDecimal(range);
BigDecimal randomNoGeneration = new BigDecimal(Math.random()); // between 0 to < 1.0
BigDecimal actualRandonNo = randomNoGeneration.multiply(rangeInBD);
return actualRandonNo.setScale(2, BigDecimal.ROUND_HALF_UP);
}
No comments:
Post a Comment