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 6 sided Die by default.
public Die(int sides)
{
rand.setSeed(System.currentTimeMillis());
this.sides = sides;
}
public int roll()
{
/* This part...
rand.nextInt() & Integer.MAX_VALUE
...is needed to ensure that nextInt
returns a positive value.
MAX_VALUE looks something like this
in memory:
01111111111111111111111111111111111
so logically anding another integer
with it preserves all of the original
integer's 1 bits except for the
negative bit.
*/
return ((rand.nextInt() & Integer.MAX_VALUE)% this.sides)+1;
}
}
public class Game
{
//TODO: Declare two private Die variables named player1 and player2 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!