JSFiddle - React, Tailwind, and code Playground
JavaScript
var uniqueRandom = {
randoms: [],
getRandom: function(){
var random = Math.floor(Math.random() * 10);
if(this.randoms.filter(function(elem){ return elem == random}).length > 0){
return this.getRandom();
}else{
this.randoms.push(random);
return random;
}
}
}
for(var i = 0; i < 10; i++){
console.log(uniqueRandom.getRandom());
}