JSFiddle - React, Tailwind, and code Playground
JavaScript
function PersistentRandom(exclusiveUpperBounds){
this.spent = [];
this.bounds = exclusiveUpperBounds;
}
PersistentRandom.prototype.getValue = function(){
if(this.spent.length != this.bounds -1){
var tmp = Math.floor(Math.random()* this.bounds);
if(this.spent.indexOf(tmp) == -1){
this.spent.push(tmp);
return tmp;
}else{
return this.getValue();
}
}else{
this.spent = [];
return this.getValue();
}
};
var pr = new PersistentRandom(11);
var x = 0;
while(x < 15){
console.log(pr.getValue());
x++;
}