Java Random Class Notes Important
Java Random Class Notes Important
Typical process:
1. Create a Random object
2. Use the object to get random values. Use one of:
nextInt() returns a random integer
nextInt(max) returns an integer random value in [0, … max )
nextDouble() returns a random value in [0.0, 1.0 )
nextBoolean() returns a random value from {true, false}
1
Random Class
Examples
2
Random class – Rock/paper/scissors
3
Random class – toss a coin
4
Random class – toss a coin using booleans
5
Random class
6
Random Number Generators
https://en.wikipedia.org/wiki/Linear_congruential_generator
7
Character class
8
Character class
Examples
Notice in the code how the Character class methods are specified
when there is no object … this may seem odd, but …
9
Character class
Example 1
public class CharacterTypes