// Возвращает случайное целое число между min (включительно) и max (не включая max)
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
class UnrepeatedRandomInteger {
constructor(min, max) {
this.min = min;
this.max = max;
this.range = [];
this.defaultRange = [];
const makeRange = () => {
const range = [];
for(let i = this.min; i <= this.max; i++) {
range.push(i);
}
this.range = range;
this.defaultRange = range;
};
makeRange();
}
random() {
const index = Math.floor( Math.random() * this.range.length );
const victim = this.range[index];
const newRange = this.range.filter(item => item !== victim);
this.range = newRange;
return victim;
}
restore() {
this.range = this.defaultRange;
}
emptify() {
this.defaultRange.forEach(item => {
console.log('i am dying slowly...', this.range);
console.log('i am gonna be dropped now and never after! ', this.random());
console.log('\n\n');
});
}
}