Question: I need to know if a number compared to a set of numbers is outside of 1 stddev from the mean, etc..

Answer: 
**10 times faster** solution than Jaime's, but **be aware** that,
as Jaime pointed out:

> 
> "While the sum of squares algorithm works fine most of the time, it
> can cause big trouble if you are dealing with **very large** numbers. You
> basically may end up with a negative variance"
> 
> 
> 

If you think you are dealing with very large numbers or a very large quantity of numbers, you should calculate using both methods, if the results are equal, you know for sure that you can use "my" method for your case.

```
    public static double StandardDeviation(double[] data)
    {
        double stdDev = 0;
        double sumAll = 0;
        double sumAllQ = 0;

        //Sum of x and sum of x²
        for (int i = 0; i < data.Length; i++)
        {
            double x = data[i];
            sumAll += x;
            sumAllQ += x * x;
        }

        //Mean (not used here)
        //double mean = 0;
        //mean = sumAll / (double)data.Length;

        //Standard deviation
        stdDev = System.Math.Sqrt(
            (sumAllQ -
            (sumAll * sumAll) / data.Length) *
            (1.0d / (data.Length - 1))
            );

        return stdDev;
    }

```
You can avoid making two passes over the data by accumulating the mean and mean-square

```
cnt = 0
mean = 0
meansqr = 0
loop over array
    cnt++
    mean += value
    meansqr += value*value
mean /= cnt
meansqr /= cnt

```

and forming

```
sigma = sqrt(meansqr - mean^2)

```

A factor of `cnt/(cnt-1)` is often appropriate as well.

BTW-- The first pass over the data in [Demi](https://stackoverflow.com/questions/895929/how-do-i-determine-the-stddev-of-a-set-of-values/896070#896070) and [McWafflestix](https://stackoverflow.com/questions/895929/how-do-i-determine-the-stddev-of-a-set-of-values/895939#895939) answers are hidden in the calls to `Average`. That kind of thing is certainly trivial on a small list, but if the list exceed the size of the cache, or even the working set, this gets to be a bid deal.