Nodejs Array Get Random getRandom()

Here you can find the source of getRandom()

Method Source Code

Array.prototype.getRandom = function() {
  return this[Math.random()*this.length|0];
}

Related

  1. getRand()
    Array.prototype.getRand = function () {
        var rand = Math.floor(Math.random() * (this.length - 0)) + 0;
        return this[rand];
    
  2. getRandom()
    Array.prototype.getRandom = function(){
      var result = this[Math.floor(Math.random()*this.length)];
      return result;
    
  3. getRandomArrayItem()
    function shuffleArray(array) {
      for (var i = array.length - 1; i > 0; i--) {
        var j = Math.floor(Math.random() * (i + 1));
        var temp = array[i];
        array[i] = array[j];
        array[j] = temp;
      return array;
    Array.prototype.getRandomArrayItem = function() {
      return this[Math.floor(Math.random()*this.length)];
    
  4. getRandomElement()
    Array.prototype.getRandomElement = function() {
      var i = getRandBetween(0, this.length-1);
      return this[i];
    function getRandBetween(lo, hi) {
      return parseInt(Math.floor(Math.random()*(hi-lo+1))+lo);
    
  5. getRandomIndex()
    Array.prototype.getRandomIndex = function(){
        return Math.floor(Math.random()*this.length);