public Equipment SelectRandomEquipment(Slot forSlot) { IList <Equipment> alternatives = allEquipment[forSlot]; if (alternatives.Count < 1) { return(null); } int[] lookup = allEquipmentRarityLookupTable[forSlot]; int total = lookup[lookup.Length - 1]; int chosen = DiceRoller.Next(0, total); int index = Array.BinarySearch(lookup, chosen); if (index < 0) //exact value not found { index = ~index; //bitwise complement will convert a negative index into the index of the "closest" value found } return(alternatives[index]); }
public static string PickRandomString(string[] alternatives) { return(alternatives[DiceRoller.Next(0, alternatives.Length)]); }
public static double PickRandomDouble(double[] options) { return(options[DiceRoller.Next(0, options.Length)]); }