im using the following code which is working. The code provide range of random values but unique one i.e. it doesn't return the same values until the full range was provided ,what do you think and doest in ES6 there is shorter way to achieve this?
var range = [10, 20];
var not = [];
function randomRange(range, n) {
if (not.length >= range[1] - range[0]) {
not.length = 0;
}
var curr = [];
var res = [];
for (let i = range[0]; i < range[1]; i++) {
if (!not.some(function(num) {
return i == num
}) && not.length < range[1] - range[0]) {
curr.push(i)
}
}
for (let i = 0; i < n; i++) {
var j = curr.splice(Math.floor(Math.random() * curr.length), 1)[0];
res[i] = not[not.length] = j;
}
return res.filter(Boolean)
}
function log(result) {
document.body.innerHTML += JSON.stringify(result) + "<br>"
}
window.onload = function() {
log(randomRange(range, 3));
log(randomRange(range, 3));
log(randomRange(range, 3));
log(randomRange(range, 3));
log(randomRange(range, 3));
log(randomRange(range, 3));
log(randomRange(range, 3));
log(randomRange(range, 3));
log(randomRange(range, 3));
log(randomRange(range, 3));
}