More Random Methods

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.
go to previous page   go to home page   hear noise   go to next page

Answer:

Yes. Use the nextBoolean() method, described below. (Or use nextInt(2).)

More Random Methods

Here are some more methods of the Random class:

long nextLong() — Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence. All possible long values, both positive and negative, are in the range of values returned.
boolean nextBoolean() — Returns a pseudorandom, boolean value.
void setSeed(long seed) — sets the seed of the random number generator. You might want to do this to repeat a sequence of random numbers in order to see the effect of some change that you made in a simulation.

There are some other methods of Random not described here.

QUESTION 13:

Think of a really great secret password for your computer account.