Just shuffle the question array and pick one after the other. In a simplified version:
var questions = [1,2,3,4,5,6,7,8,9,10];
function shuffle(a) {
var cidx, ridx,tmp;
cidx = a.length;
while (cidx != 0) {
ridx = Math.floor(Math.random() * cidx);
cidx--;
tmp = a[cidx];
a[cidx] = a[ridx];
a[ridx] = tmp;
}
return a;
}
function* get_one(arr){
var idx = arr.length;
while(idx != 0)
yield arr[idx--];
}
questions = shuffle(questions);
console.log(questions);
var nextq = get_one(questions);
var alen = questions.length -1;
while(alen--)
console.log(nextq.next().value);
You don't need that fancy generator, you can just get one after the other in a simple loop if you prefer that.