Random number can be generated using two ways. You can generate random value using Random class defined in java.util package. long array[] = new long[5]; Arrays.fill(array, 30); The method also has several alternatives which set a range of an array to a particular value: generate random number into 2d arrays . = number 1).. Java has a "Random" class that lets you generate a random number you use to implement calculations in your Java source code. Syntax to get random one digit number:: int i=rand()%10; cout<<"Random number::"<