Next: for loops
Up: Assignment 10: Arrays
Previous: Assignment 10: Arrays
The book shows examples of how to use the Math.random method to
generate random doubles between 0.0 and 1.0 (including both).
By multiplying and adding 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 (including both).
- 2.
- Write a method called randIntArray that is similar to
randomArray on page 112, 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 Downey
1999-11-09