Normal distribution array function I have a function that produce an array with values that are Gaussian (normal) distribution. If you plot the values on a graph, it would look something like this:



Is there any way to improve on the code?

private static IComparable[] NonUniformDistributionsGaussian(int startNumber,int arraySize)
    {
        IComparable [] arr = new IComparable[arraySize];
        Double[] intervals = { ((1.00 / 6.00) * arraySize), ((2.00 / 6.00) * arraySize),
                                 ((3.00 / 6.00) * arraySize),((4.00 / 6.00) * arraySize),
                                 ((5.00 / 6.00) * arraySize), ((6.00 / 6.00) * arraySize) };

        for (var i = 0; i &lt; arraySize; i++)
        {

            if (i &lt;= (int)intervals[0])
            {
                startNumber = startNumber + 1;                   
            }

            else if ( i &lt;= (int)intervals[1])
            {
                 startNumber = startNumber  + 2;                    
            }
            else if (i &lt;= (int)intervals[2])
            {
                startNumber = startNumber + 3;
            }
            else if (i &lt;= (int)intervals[3])
            {
                startNumber = startNumber - 3;
            }
            else if (i &lt;= (int)intervals[4])
            {
                startNumber = startNumber - 3;
            }
            else 
            {
                 startNumber = startNumber  - 2;                     
            }
            arr[i] = startNumber;
        }
        return arr;
    }
As the conditions of the if statements only depending on some fixed numbers and the arraysize input parameter these values can be precalculated.  

int oneThirdArraySize = (int)((1.00 / 3.00) * arraySize);


and then used in the loop like  

for (var i = 0; i &lt; arraySize; i++)
{

    if (i &lt;= oneThirdArraySize)
    {
        startNumber = startNumber + 1;
        arr[i] = startNumber;
    }
    // and so on
}


By precalculation of the right side values of the if conditions outside of the loop you can speed this up because right now you do these calculation up to two times for every iteration.  

But we can do better because you are using some magic numbers here which we can hide behind some meaningful const variables.  

private static const double oneThird = 1d / 3d;
private static const double twoThird = 2d / 3d;  


In this way the calculations need to be changed to  

int oneThirdArraySize = (int)(oneThird * arraySize);