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

4. Write a function called mean that will return the average value of an integer array....
4. Write a function called mean that will return the average value of an integer array. The integer array and its length must be passed to the function as parameters. 5.Write a function called max that will return the index of the max value of an integer array. The integer array and its length must be passed to the function as parameters. E.g. array = {1,2,3,4,5,6,7,8,9,0} max = 9 index = 8 6.Write a function called variance that calculates and...
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 calculate and return the factorial value of any positive integer as...
Write a C function to calculate and return the factorial value of any positive integer as an argument. Then call this function from main() and print the results for the following input values: 2, 3,4, 5, 10, 15 What is the maximum value of an integer for which factorial can be calculated correctly on a machine using your algorithm?
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...
(Palindrome integer) Write the methods with the following headers // Return the reversal of an integer,...
(Palindrome integer) Write the methods with the following headers // Return the reversal of an integer, i.e., reverse(456) returns 654 public static int reverse(int number) // Return true if number is a palindrome public static boolean isPalindrome(int number) Use the reverse method to implement isPalindrome. A number is a palindrome if its reversal is the same as itself. Write a test program that prompts the user to enter an integer and reports whether the integer is a palindrome. Here is...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT