Example #1
0
        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]);
        }
Example #2
0
 public static string PickRandomString(string[] alternatives)
 {
     return(alternatives[DiceRoller.Next(0, alternatives.Length)]);
 }
Example #3
0
 public static double PickRandomDouble(double[] options)
 {
     return(options[DiceRoller.Next(0, options.Length)]);
 }