Below Java program example will produce a random number from 0 to 60 (0 to limit-1 range).
public class Random { public static int rand(int limit) { return (int) (Math.random() * limit); } public static void main(String[] args) { System.out.println("The random number between 0 to 60 is " + rand(61)); System.out.println("Another random number between 0 to 60 is " + rand(61)); System.out.println("Another random number between 0 to 60 is " + rand(61)); } }
The outcome from the above run is as follows:-
The random number between 0 to 60 is 52 Another random number between 0 to 60 is 22 Another random number between 0 to 60 is 33
The outcome will vary each time you run the program!