} // end method getRandomBuildDesc private string RandomWeightedRoller(string DefaultResult, Dictionary <string, int> WeightedTable) { string ResultText = DefaultResult; // add up total_weight int total_weight = 0; foreach (var TableData in WeightedTable) { total_weight += TableData.Value; } // roll from 1 to total_weight int RollToCompare = diceBag.RawRoll1To(total_weight); // loop the race list int RangeLow = 0; int RangeHigh = 0; foreach (var TableData in WeightedTable) { // move high to low, and add the weight of the next race to high RangeLow = RangeHigh + 1; RangeHigh += TableData.Value; // if we're between high and low, that's our race if (RangeLow <= RollToCompare && RollToCompare <= RangeHigh) { ResultText = TableData.Key; } } // end foreach return(ResultText); } // end method RandomWeightedRoller
// ----- public string PickFromList(List <string> pick_list) { // given a list of strings, determine the size of the list and // ... random roll to choose one to return int index = diceBag.RawRoll1To(pick_list.Count) - 1; string picked_word = pick_list[index]; return(picked_word); } // end public int PickFromList