Whenever an element is selected, move it to the back of the array and randomly select array.slice(0, -5) from the slice of the original array.
var a = ["Roger", "Russell", "Clyde", "Egbert", "Clare", "Bobbie", "Simon", "Elizabeth", "Ted", "Caroline"]; var chooseName = function () { var unique = true; num = Math.floor(Math.random() * a.length - 5); name = a.splice(num,1); a.push(name); } window.addEventListener("keypress", function (e) { var keycode = e.keyCode; if (keycode == 13) { chooseName(); } }, false);
EDIT: This also has a side effect of the fact that any variables do not match the list of unfair flaw, which they will not consider in the first N calls. If this is a problem for you, perhaps try storing a static variable somewhere to keep track of the size of the fragment used and make the most of it in B (in this case 5). eg.
var a = ["Roger", "Russell", "Clyde", "Egbert", "Clare", "Bobbie", "Simon", "Elizabeth", "Ted", "Caroline"]; B = 5;
source share