Chapter 6 Section 10 "Random Number Generation" - generate random numbers using the random method of the Math class - random method - pseudorandom number generator - not truly random - eventually the numbers returned will repeat - returns a double >= 0.0 and < 1.0 - generally want integers - conversion so that number generated will fall in desired range [min, max] - Y = floor(X * (max - min + 1) ) + min - special case for min = 1: Y = floor( x * max ) + 1 - code version: int randomNumber = (int) (Math.floor(Math.random() * (max-min+1)) + min); - timing execution - use the Date class to grab the start time and end time - Date startTime = new Date(); - put the difference in a long to get elapsed time in milliseconds - long elapsedTime = endTime.getTime() - startTime.getTime(); - rough estimate because varies with the CPU that it is run on - if difference is 0, means that it was so fast we couldn't measure it, not that it took no time - break statement - can be used in things other than switch; e.g., if statement or a loop to immediately stop execution - exit a program using System.exit(0); Quick Check 1. int randomNumber = Math.floor( Math.random() * (50 - 20 + 1) ) + 20; 2. about 5250 s