JavaScript - Random Numbers

function Random_Int(min_1, max_1) {

    // Generate a random number between min and max

    return Math.floor(Math.random() * (max_1 - min_1 + 1)) + min_1;

}

// Define the range for random numbers

const min_1 = 1;

const max_1 = 100;

 

// Generate and print 5 random numbers

for (let i = 0; i < 5; i++) {

    let random_Num = Random_Int(min_1, max_1);

    console.log(`Random Number: ${random_Num}`);

}

Explanation of the JavaScript Code:

Random_Int(min_1, max_1) Function: This function generates a random integer between the specified min and max values, inclusive. It uses Math.random() to generate a random number between 0 and 1, scales it to the desired range, and then rounds it down to the nearest integer using Math.floor().

Range Definition: We define the min and max variables to specify the range of the random numbers. In this example, they are set to 1 and 100, respectively.

For Loop: A for loop runs five times. In each iteration, it calls the Random_Int(min_1, max_1) function to generate a random number within the specified range and prints it to the console using console.log().