MBGen.WordList.PickByWeight C# (CSharp) Method

PickByWeight() private method

private PickByWeight ( List items, LongRandom rand ) : int
items List
rand LongRandom
return int
        private int PickByWeight(List<int> items, LongRandom rand)
        {
            int total = TotalWeights(items);
            int randomNumber = rand.Next(0, total);
            int selectedIndex = 0;
            int count = items.Count;
            for (int i = 0; i < count; i++)
            {
                if (randomNumber < this.Weights[items[i]] + this.DistWeights[items[i]])
                {
                    selectedIndex = i;
                    break;
                }
                randomNumber -= this.Weights[items[i]] + this.DistWeights[items[i]];
            }
            return selectedIndex;
        }

Same methods

WordList::PickByWeight ( string className, LongRandom rand ) : int