We will see three Java packages or classes that can generate a random number between 1 and 10 and which of them is the. Using the random Method. Java program to generate floating-point numbers between 1 to 100.
In Java there is three-way to generate random numbers using the method and classes.
If you want to specific range of values you have to multiply the returned value with the magnitude of the range. Public int getRandomNumberint min int max return int Mathrandom max - min min. An object of Random class is initialized and the method nextInt nextDouble or nextLong is used to generate random number. The Mathrandom function returns a floating-point pseudo-random number in the range 0 to less than 1 inclusive of 0 but not 1 with approximately uniform distribution over that range which you can then scale to your desired range.