We can assign random values to an array by two approaches. If we do not pass any arguments to the nextInt() method, then it will assign some arbitrary random value of integers range in Java and if we pass some argument to the nextInt() method then it will generate numbers in the range between 0 to the argument passed
CODE
import java.util.Random;
import java.util.*;
public class RandomArrayValues {
public static void main(String[] args) {
int n = 5;
int[] randomArray = new int[n];
Random random = new Random();
for (int i = 0; i < n; i++) {
randomArray[i] = random.nextInt();
}
System.out.println(“Random assigned value of Array are: “);
for (int value : randomArray) {
System.out.print(value+” “);
}
}
}
OUTPUT
Random assigned value of Array are: -170019732 2032213863 -1596767761 -1668938134 -210148393