using System.Collections.Generic;
private static void Main(string[] args)
var edges = new Dictionary<int, double>
var dice = new Dice(edges);
var actualProbabilities = edges.Select(p => p.Key).ToDictionary(p => p, p => 0);
for (var i = 0; i < rollCount; i++)
actualProbabilities[edge]++;
Console.WriteLine($"Roll #{i}: Edge {edge}");
foreach (var p in actualProbabilities)
Console.WriteLine($"Edge #{p.Key} has actual probability {p.Value * 1.0d / rollCount}");
private readonly Roulette _roulette;
public Dice(Dictionary<int, double> edges)
_roulette = CreateRoulette(edges);
var sector = _roulette.Roll();
private static Roulette CreateRoulette(Dictionary<int, double> edges)
var sectors = new List<Sector>();
const double onePercentLength = 1.0d / 100;
foreach (var edge in edges)
var sectorTo = sectorFrom + edge.Value * onePercentLength;
var sector = new Sector(edge.Key, sectorFrom, sectorTo);
var roulette = new Roulette(sectors);
public double From { get; }
public double To { get; }
public Sector(int id, double from, double to)
private static readonly Random _random = new Random();
private readonly List<Sector> _sectors;
public Roulette(List<Sector> sectors)
var r = _random.NextDouble();
foreach (var sector in _sectors)
if (IsValueInSector(r, sector))
private static bool IsValueInSector(double value, Sector sector)
return value >= sector.From && value < sector.To;