(JavaScript)sometimes returns as undefined. Why?

function getComputerChoice(randomLetterGen){

function randomLetterGen(){

    function randomNumGen(){
        return Math.floor(Math.random()*3);
    }

    let word = "rps";
    return word.charAt(randomNumGen());
}

let cpuInput;

if (randomLetterGen() == "r"){
    cpuInput = "rock";
} else if (randomLetterGen() == "p"){
    cpuInput = "paper";
} else if (randomLetterGen() == "s") {
    cpuInput = "scissors";
}
return cpuInput;

}

console.log(getComputerChoice());

I think there is an undefined option because of the ‘let cpuInput;’ but I dont understand why. I thought the if statement redefined the variable. Also, the undefined option only logs when ‘Math.random()*3’ is 2 or above. It doesnt appear otherwise. Why?