// function to generate a random tweet tweet function ranDom (arr) { var index = Math.floor(Math.random()*arr.length); return arr[index]; };Este es el codigo usado
Funciona bien aquí:
function ranDom (arr) { return arr[Math.floor(Math.random()*arr.length)]; }; var items = [254, 45, 212, 365, 2543]; console.log(ranDom(items));En general, puede agregar esta línea al comienzo de su función
if (arr === undefined){ return DEFAULT_VALUE; \\define your default value for this case.. }para manejar este caso.
Pero debe investigar por qué su arr no está definido desde la llamada a la función.