The Random Class

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
Historical topic: Java appletsModern web browsers do not run Java applets. The Applet API was deprecated for removal before Java 25 and was removed in Java 26. Treat applet examples on this page as historical object-oriented/GUI examples; for new desktop interfaces use Swing where appropriate or JavaFX/OpenJFX.

Answer:

Put them on and look at this applet. Possibly there would be a stereo effect (or possibly not). I get a mild effect.

The Random Class

The Random class creates an object that outputs random integers. For example:

Random randNum = new Random();  // create a Random number object

. . .

int someInt = Math.abs( randNum.nextInt() )%200   // someInt gets 
                                                  // a number from 0 to 199

The object referred to by randNum has a method nextInt() that will return an int randomly selected from the entire range of ints, negative and positive. Math.abs() can be used to make the returned int postive. Doing remainder division by 200 on that gives us an int 0 ... 199.

QUESTION 15:

Say that you wanted to draw 1000 circles of radius 5 at random locations on the screen. What would you do?