namespace CoinBoxProbability
public Coin First { get; private set; }
public Coin Second { get; private set; }
public Box(Coin first, Coin second)
public Tuple<Coin, Coin> PickCoins() =>
Program.Random.Next(2) == 0
? Tuple.Create(First, Second)
: Tuple.Create(Second, First);
public Box[] Boxes { get; private set; } =
new Box(Coin.Gold, Coin.Gold),
new Box(Coin.Gold, Coin.Silver),
new Box(Coin.Silver, Coin.Silver),
public Box PickBox() => Boxes[Program.Random.Next(Boxes.Length)];
public static Random Random = new Random();
public const int IterationsCount = 10000;
static void Main(string[] args)
int silverCount = 0, goldCount = 0;
for (var i = 0; i < IterationsCount; i++)
var (firstCoin, secondCoin) = set.PickBox().PickCoins();
if (firstCoin != Coin.Gold)
if (secondCoin == Coin.Gold)
var totalCases = silverCount + goldCount;
Console.WriteLine($"Общее количество итераций: {IterationsCount}, первая вытащенная монета золотая в {totalCases} случаях ({(double)totalCases / IterationsCount:P})");
Console.WriteLine($"Вторая монета золотая в {goldCount} случаях ({(double)goldCount/totalCases:P} от {totalCases})");