logo CodeStepByStep logo

randomExpressions

Language/Type: Java parameters Random

Suppose that the following variable has been declared:

Random rand = new Random();

Fill in the boxes to produce expressions that will generate random numbers in the provided ranges. Create an expression of the form:

rand.nextInt(a) * b + c

For example, to create a random integer from 1 to 5 inclusive, you'd write, rand.nextInt(5) + 1.

from 0 to 3 inclusive: a =
from 5 to 10 inclusive: a =
from 5 to 10 inclusive: c =
from -4 to 4 inclusive: a =
from -4 to 4 inclusive: c =
a random even integer from 16 to 28 inclusive: a =
a random even integer from 16 to 28 inclusive: b =
a random even integer from 16 to 28 inclusive: c =

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.