Next: for loops
Up: Assignment 11: Arrays
Previous: Assignment 11: Arrays
The book shows examples of how to use the Math.random
method to generate random doubles between 0.0 and 1.0. By
scaling and shifting these values, you can generate random values
in a given range. For example, Math.random() * 100.0 + 10.0
yields a double between 10 and 110.
- 1.
- Write a method called randInt that takes two arguments,
low and high, and that returns a random integer between
low and high.
- 2.
- Write a method called randIntArray that is similar to
randomArray on page 115, except it should take two additional
arguments, low and high, and it should return an
array of integers in the range from low to high.
- 3.
- Write a method called prIntArray that takes an array
of integers and prints them. Use it to debug randIntArray.
Allen B. Downey
1999-04-21