public static double StdDevP(this IEnumerable source) { return StdDevLogic(source, 0); } public static double StdDev(this IEnumerable source) { return StdDevLogic(source, 1); } private static double StdDevLogic(this IEnumerable source, int buffer = 1) { if (source == null) { throw new ArgumentNullException("source"); } var data = source.ToList(); var average = data.Average(); var differences = data.Select(u => Math.Pow(average - u, 2.0)).ToList(); return Math.Sqrt(differences.Sum() / (differences.Count() - buffer)); }