Generate Random Numbers Java

Generate Random Numbers Java


Many a times random number generation is required in coding, especially in testing. When different sequence of numbers are passed multiple times, a correct result should to be obtained; testing requires this. Sometimes, the same sequence of random numbers is also required multiple times in testing; when the same sequence is passed number of times, the same result should be obtained.

To generate random numbers two ways exist in Java – using Math.random() method and using java.util.Random class.

The code with good explanation is given in class Random

Leave a Reply

Your email address will not be published. Required fields are marked *