Just hack the function for you.
var randElemsWithoutReplace = function (ls_, n) { var ls = ls_.slice(); var selections = []; for (var i = 0; i < n; i++) { selections.push(ls.splice(Math.floor(Math.random()*ls.length), 1)[0]); } return selections; };
The arguments you need to pass are the array you want to select, and how many elements you want to select. For example, if I have
var myArray = ['a', 'b', 'c', 'd', 'e'];
And I want three different elements to be randomly selected from this array, I would write
randElemsWithoutReplace(myArray, 3);
This will return an array with three randomly selected elements.
source share