Search code examples
javabigdecimal

JAVA -BigDecimal randomly between 0.00 to 1000.00


I need method which will generate a big decimal numbers between 0.00 to 1000.00. anyone can help? In google i can find only between 0-1 or something else... but this doesn't help me Thank You!


Solution

  • new BigDecimal(BigInteger.valueOf(new Random().nextInt(100001)), 2)
    

    Generates an integer uniformly at random between 0 and 10,000 inclusive, and creates a BigDecimal with that value divided by 100.