public static double StandardDeviation(IEnumerable‹double› sequence)
{
double sum = 0;
double sumOfSquares = 0;
double count = 0;
foreach (var item in sequence)
{
count++;
sum += item;
sumOfSquares += item * item;
}
var variance = sumOfSquares - sum * sum / count;
return Math.Sqrt(variance / count);
}