Set a random initial direction of motion
After seeding the random number generator in
Listing 2,
- The program calls the rand function
- Using the modulus operator approach described in
Figure 2
- To generate a random number between 0 and 3 inclusive.
This value is assigned to the variable named dir
- To cause the initial direction of motion of the ball in
Figure 1 to be random.