Need help with picking a random number

Not sure if this is of any, I’ve been using chat gpt to generate a few very small JavaScript functions, so I entered your request and it returned a valid function (I think?), very easy to pass it the variables it requires.
Website you can paste and test it

function getRandomNumberWithGap(min, max, excludeStart, excludeEnd) {
// Create an array to hold the valid numbers
let validNumbers = ;

// Populate the array with numbers excluding the specified gap
for (let i = min; i <= max; i++) {
    if (i < excludeStart || i > excludeEnd) {
        validNumbers.push(i);
    }
}

// Pick a random number from the valid numbers
let randomIndex = Math.floor(Math.random() * validNumbers.length);
return validNumbers[randomIndex];

}

// Example usage
let min = 1;
let max = 10;
let excludeStart = 6;
let excludeEnd = 8;

let randomNumber = getRandomNumberWithGap(min, max, excludeStart, excludeEnd);
console.log(“Random number:”, randomNumber);

1 Like