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 Python function next_Sophie_Germain(n), which on input a positive integer n return the smallest Sophie...
Write a Python function next_Sophie_Germain(n), which on input a positive integer n return the smallest Sophie Germain prime that is greater or equal to n.
Write a function that will accept a list of numbers and an integer (n). The function...
Write a function that will accept a list of numbers and an integer (n). The function should return a list containing every nth item from the input list, always starting with the first item in the list. The original list should not be modified. For example, if the function is passed the list [8, 3, 19, 26, 32, 12, 3, 7, 21, 16] and the integer 3, it will return the list [8, 26, 3, 16] If the function is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT