Exercise 2.2
- Write statements that will make the int variable number
take on a random value distributed over the given set.
- {1, 2, 3, ..., 10}
- {1, 2, 3, ..., 54}
- {5, 10, 15, ..., 100}
- {-5, -4, -3, ..., 5}
- {100, 110, 120, ..., 300}
- {a, a + b, a + 2b, ..., a + kb} where a, b,
k are integers
- Write statements that will assign the real variable randReal a random
value from the set
{1.00, 1.25, 1.50, ..., 4.00}.
- Write a program that draws red squares at three random
locations on the screen.
- Modify the program in part (a) so that the size of each square will be a random value between 25 and 100 pixels.
- Modify the program in part (b) so the the colours of the squares will also be random.
|
|