public SquareRandom(SquareType type, Dictionary <Color, int> colorWeights, int seed = 0) { this.Type = type; this.Random = new Random(seed); this.ColorRandom = new WeightRandom <Color>(colorWeights); this.ColorRandom.InitRandom(Random.Next()); }
public void Init(Dictionary <SquareType, int> squareWeights, Dictionary <SquareType, Dictionary <Color, int> > weights, int seed) { this.random = new Random(seed); var squareDict = new Dictionary <SquareRandom, int>(); foreach (var kvp in squareWeights) { var sr = SquareRandomFactory.Create(kvp.Key, weights[kvp.Key], this.random.Next()); squareDict.Add(sr, kvp.Value); } this.weightRandom = new WeightRandom <SquareRandom>(squareDict); this.weightRandom.InitRandom(this.random.Next()); }
public void Run() { this.InitData(); var weightRandom = new WeightRandom <int>(this.weights); weightRandom.InitRandom(0); for (var i = 0; i < RunTimes; ++i) { var v = weightRandom.Next(); ++this.result[v]; } this.Print(); }