Write a method called randomInRange that accepts two integer parameters representing a range. The method should return a random integer in the specified range (inclusive). Assume that the first parameter is greater than the second.

What will be an ideal response?


public int randomInRange (int first, int second)
{
Random generator = new Random();
int range = second – first + 1;
return generator.nextInt(range) + first;
}

Computer Science & Information Technology

You might also like to view...

If an algorithm needs 4 seconds to run on a set of 2 input data, 9 seconds for 3, 16 for 4, and so on, then what is the complexity of this algorithm?

a. Quadratic b. Linear c. Logarithmic d. This can't be determined

Computer Science & Information Technology

Managing the ________ is the second major task of an operating system which includes managing all programs installed on your computer

A) hardware B) data C) peripherals D) application software

Computer Science & Information Technology

The courts have indicated that subscribers to ISPs have a reasonable expectation of privacy in their basic subscriber information

Indicate whether the statement is true or false.

Computer Science & Information Technology

A manual calculator implements algorithms autonomously.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology