Question

In: Computer Science

Challenge 4 – Random Integer in Range Write a function to return a random integer between...

Challenge 4 – Random Integer in Range Write a function to return a random integer between a minimum value and maximum value.

var ival = IntRandomRange(, );

Solutions

Expert Solution

Program:

<html>
<head>
<script language="javascript">
function IntRandomRange(minValue,maxValue)
{
var value;
value=Math.floor(Math.random()*maxValue+minValue);
return value;
}
</script>
</head>
<body>
<script language="javascript">
var max,min;
min=parseInt(prompt("Enter the minimum value: "));
max=parseInt(prompt("Enter the maximum value: "));
var ival=IntRandomRange(min,max);
document.write("Minimum value: "+min);
document.write("<br>Maximum value: "+max);
document.write("<h3>A random number between "+min+" and "+max+" is "+ival+"</h3>");
</script>
</body>
</html>

Output:


Related Solutions

Write a program that repeatedly generates a random integer in the range [1, 100], one integer...
Write a program that repeatedly generates a random integer in the range [1, 100], one integer at a time, and displays the generated numbers on the screen according to the following rules: If the second number generated is greater than the first number, they are displayed on the screen in the order of their input and while the next random number generated is greater than the previous one, the random number is displayed on the screen and the program continues....
Write a program that repeatedly generates a random integer in the range [1, 100], one integer...
Write a program that repeatedly generates a random integer in the range [1, 100], one integer at a time, and displays the generated numbers on the screen according to the following rules: If the second number generated is greater than the first number, they are displayed on the screen in the order of their input and while the next random number generated is greater than the previous one, the random number is displayed on the screen and the program continues....
Write a program that repeatedly generates a random integer in the range [1, 100], one integer...
Write a program that repeatedly generates a random integer in the range [1, 100], one integer at a time, and displays the generated numbers on the screen according to the following rules: If the second number generated is greater than the first number, they are displayed on the screen in the order of their input and while the next random number generated is greater than the previous one, the random number is displayed on the screen and the program continues....
write a function named as cubeCalculator that takes an integer pointer as function and return its...
write a function named as cubeCalculator that takes an integer pointer as function and return its cube value , you are required to compute the cube of a number using pointer notation , return the result as an integer value , use c++
Write a C function to add the elements of two same-sized integer arrays and return ptr...
Write a C function to add the elements of two same-sized integer arrays and return ptr to a third array. int *addTwoArrays(int *a1, int *b1, int size); The function should follow the following rules: If the sum for any element is negative, make it zero. If a1 and b1 point to the same array, it returns a NULL If any input array is NULL, it returns a NULL. Please call this function with the following arrays and print the sums...
Write a function named “compileStats” that has 4 parameters: a vector of integers, an integer representing...
Write a function named “compileStats” that has 4 parameters: a vector of integers, an integer representing the smallest value contained in the vector, an integer representing the largest value contained in the vector, and a double that represents the average of the values in the vector. The compileStats function will not “return” a value, it will set the Pass By Reference parameters to the correct values (smallest, largest, and average). Use the following main function in driver1b.cpp as a starting...
Problem 4.Step 1: Generate a random integer between 3 and 6. Set A to be the...
Problem 4.Step 1: Generate a random integer between 3 and 6. Set A to be the value of the generated number.Step 2: Generate a random integer between 3 and 6. Set B to bethe value of the generated number.You are running a camp of 30 students, including John and Jane.3a.) What is the total possible ways you can arrange 2 focus groupsof students one group being size A(from step 1), and the other sizeB.3b.) What is the probability that John...
C programming: Define a function computer_choose that chooses a random integer between 1 and 1000 (inclusive)....
C programming: Define a function computer_choose that chooses a random integer between 1 and 1000 (inclusive). Note: the tests call your function 1000 times to verify that no results are <0 or >1000. Rarely, this can score an incorrect function as correct.
Write a C++ console application to simulate a guessing game. Generate a random integer between one...
Write a C++ console application to simulate a guessing game. Generate a random integer between one and 100 inclusive. Ask the user to guess the number. If the user’s number is lower than the random number, let the user know. If the number is higher, indicate that to the user. Prompt the user to enter another number. The game will continue until the user can find out what the random number is. Once the number is guessed correctly, display a...
Using C++ Write a template function that accepts an integer parameter and returns its integer square...
Using C++ Write a template function that accepts an integer parameter and returns its integer square root. The function should return -1, if the argument passed is not integer. Demonstrate the function with a suitable driver program .
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT