Question: Make these programs work with eachother for a working game in java import java.security.SecureRandom; / * The difference between java.security.SecureRandom and java.util.Random is described here
Make these programs work with eachother for a working game in java
import java.security.SecureRandom;
The difference between
java.security.SecureRandom
and
java.util.Random
is described here
public class Die
private SecureRandom rand new SecureRandom;
private int sides;
TODO: Create an overloaded constructor for the Die that takes no arguments and creates a sided Die by default.
public Dieint sides
rand.setSeedSystemcurrentTimeMillis;
this.sides sides;
public int roll
This part...
rand.nextInt & Integer.MAXVALUE
is needed to ensure that nextInt
returns a positive value.
MAXVALUE looks something like this
in memory:
so logically anding another integer
with it preserves all of the original
integer's bits except for the
negative bit.
return randnextInt & Integer.MAXVALUE this.sides;
public class Game
TODO: Declare two private Die variables named player and player here. This provides a reference to Die from Game, which is an example of composition.
public Game
TODO: Initialize the two Die variables here. DO NOT pass the number of sides to the Dice's constructors.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
