Question: According to the following C# template : using System; using System.Collections.Generic; public class Dice { protected Random rnd; public Dice(int seed) { rnd = new
According to the following C# template :
using System;
using System.Collections.Generic;
public class Dice {
protected Random rnd;
public Dice(int seed) {
rnd = new Random(seed);
}
public virtual int Next() {
return rnd.Next(1,7);
}
}
public class Program
{
public static void Main()
{
}
}
Here we have a base class called Dice.
public class Dice {
protected Random rnd;
public Dice(int seed) {
rnd = new Random(seed);
}
public virtual int Next() {
return rnd.Next(1,7);
}
}
In the following, we have created a class called FairRandom.
public class FairRandom {
private int lastNumber = 3;
private Random rnd;
public FairRandom() {
Console.WriteLine("Enter Seed Value");
string userInput = Console.ReadLine();
int seed = Convert.ToInt32(userInput);
rnd=new Random(seed);
}
public int Next() {
int num;
if (lastNumber == 6) {
num = rnd.Next(1,3);
}
else if (lastNumber == 1) {
num = rnd.Next(5,7);
}
else {
num = rnd.Next(1,7);
}
lastNumber = num;
return num;
}
}
Please copy and paste the class FairRandom into the template and update the classes so that FairRandom is a proper sub-class of Dice without any compilation errors and warnings.
Notice that FairRandom should have a custom constructor that takes in an integer random seed, and please run the program to make sure the random seed is working after you do the changes.
Copy and paste the complete program here:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
