/**
 * @copyright nhcarrigan
 * @license Naomi's Public License
 * @author Naomi Carrigan
 */
/**
 * Module to select a random value from an array.
 * @param array - The array to select from.
 * @param weight - Optional parameter to prefer lower or higher values.
 * @returns The selected value.
 */
export const getRandomValue
  = <T>(array: Array<T>, weight?: "low" | "high"): T => {
    let random = Math.floor(Math.random() * array.length);
    switch (weight) {
      case "low":
        random = Math.min(
          Math.floor(Math.random() * array.length),
          Math.floor(Math.random() * array.length),
          Math.floor(Math.random() * array.length),
        );
        break;
      case "high":
        random = Math.max(
          Math.floor(Math.random() * array.length),
          Math.floor(Math.random() * array.length),
          Math.floor(Math.random() * array.length),
        );
        break;
      default:
        break;
    }
    return array[random] as T;
  };
