1. solution: define Array prototype
Array.prototype.random = function () {
return this[Math.floor((Math.random()*this.length))];
}
that will work on inline arrays
[2,3,5].random()
and of course predefined arrays
list = [2,3,5]
list.random()
2. solution: define custom function that accepts list and returns element
get_random = function (list) {
return list[Math.floor((Math.random()*list.length))];
}
get_random([2,3,5])