make a funktion that returns a random list of integrere in javascript

index.tsx
/**
 * Returns an array of random integers
 * @param {number} length - Length of the array to be returned
 * @param {number} start - Starting range of the random integer
 * @param {number} end - End range of the random integer
 * @returns {Array} - Array of random integers
 */
function generateRandomIntegers(length, start, end) {
  const result = [];
  for (let i = 0; i < length; i++) {
     result.push(Math.floor(Math.random() * (end - start + 1) + start));
  }
  return result;
}
486 chars
15 lines

Example usage:

index.tsx
const randomIntegers = generateRandomIntegers(5, 1, 10);
console.log(randomIntegers);
// Output: [5, 1, 7, 9, 2]
113 chars
4 lines

gistlibby LogSnag