using System;
using System.Collections.Generic;
public class FairRandom {
private int lastNumber; // we always need to know the last number generated
// so it's a private field
private Random rnd;
// we would also like to reuse the same Random object
public FairRandom () // This is a custom constructor
{
lastNumber = 3;
rnd = new Random(3);//This is a specific seed I provided
}
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;
public class Program
public static void Main()
FairRandom frnd = new FairRandom();
for (int i=0;i<100;i++)
Console.WriteLine(frnd.Next()); //unable to access rnd in the class FairRandom