JSFiddle - React, Tailwind, and code Playground
JavaScript
function shuffle(arr) {
for (let i = 0; i < arr.length; i += 1) {
const other = Math.floor(Math.random() * arr.length);
const buffer = arr[i];
arr[i] = arr[other];
arr[other] = buffer;
}
return arr;
}
function deGenerate(len, {min, max}) {
const delta = Math.ceil((max - min) / len);
if (delta === 1) throw new Error('check args');
const getRandom = () => Math.ceil(Math.random() * delta );
const output = [];
for (let i = 0; i < len; i += 1) {
output.push(i * delta + getRandom());
}
return shuffle(output);
}
console.log(deGenerate(100, {min: 0, max: 500}))