public static int GetRandomTriangularFavoredIndex(int length) { if (length > Triangular.MaxInt32) { throw new ArgumentOutOfRangeException(nameof(length), length, $"Exceeds maximum Int32 value of {Triangular.MaxInt32}."); } var possibilities = (int)Triangular.Forward(length); var selected = RandomUtilities.Random.Next(possibilities); var r = Triangular.Reverse(selected); Debug.Assert(r < length); return(r); }