'How to generate a random char array of a specific length using specific characters

I am trying to take this char array here:

char[] options = {'F','Z','P','E','N','T','L','C','D','O'};

and generate a new random char array of a specific length. Like this:

char[] results ={'Z','E','L','C'...} all the way up to a length of 70 characters long. I've already tried to create a new char such as char[] results = new char[70] and then using a for loop to try to get this. But for some reason my mind is blanking. Can anybody refresh me? Thanks all



Solution 1:[1]

Kind of straightforward solution

char[] options = {'F','Z','P','E','N','T','L','C','D','O'};
char[] result = new char[70];
Random r=new Random();
for(int i=0;i<result.length;i++){
    result[i]=options[r.nextInt(options.length)];
}

Solution 2:[2]

private static char[] options = {'F','Z','P','E','N','T','L','C','D','O'};

public static char[] createRandomArray() {
    Random r = new Random();

    char[] arr = new char[70];
    for (int i = 0; i < arr.length; i++) {
        arr[i] = options[r.nextInt(options.length)];
    }
    return  arr;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zr0gravity7
Solution 2 zr0gravity7