Get random number between 0 and 1 in java

Previous
Next

In this post, we will see how to get random number between 0 to 1 in java. We have already seen random number generator in java.

We can simply use Math.random() method to get random number between 0 to 1.

Math.random method returns double value between o(inclusive) to 1(exclusive).

When you run above program, you will get below output

Random number 1 : 0.7411678523235552
Random number 2 : 0.2933148166792703
Random number 3 : 0.48691199704439214
Random number 4 : 0.6151816544734755

That’s all about how to get random number between 0 and 1 in java.

Previous
Next

Add Comment