using System;
using System.Collections.Generic;
public class FairRandom {
private int lastNumber = 3; // 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
/* this is a constructor */
/*
* a constructor will have these properties
* 1. the constructor must have the same name of the Class
* 2. a constructor can include different parameters
* 3. you can not create a same constructor-parameters that existed alrady
for calss A, you can not have 2 A() constructor, also you can not have 2 A(int x) constructor
but you can have one A() and one A(int x) constructor in class A
* 4. a constructor should be public, but you can also define other type in different situation
*/
public FairRandom() {
rnd = new Random();
}
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 rnd = new FairRandom();
for (int i=0;i<100;i++)
Console.WriteLine(rnd.Next());