c# for loop arithmetic
<p>This program I am writing for a class uses "random" numbers to generate arrival(arrival[i]) and service times(service[i]) for jobs. My current problem is with the arrival time. To get the arrival time, I call a function named exponential and add the returning value to the previous arrival time (arrival[i-1]) in the array. For some reason I don't understand, the program is not using the previous value of the array for the addition, but rather a seemingly random value (1500,1600 ect). But I know the real values set in the array are all below 5. This should be simple array arithmetic in a for loop but I cannot figure out what is going wrong.</p>

<pre><code>namespace ConsoleApplication4
{

class Program
{
    static long state;

    void putseed(int value)
    {
        state = value;
    }

    static void Main(string[] args)
    {
        Program pro = new Program();
        double totals = 0;
        double totald = 0;
        pro.putseed(12345);
        double[] arrival = new double[1000];
        double[] service = new double[1000];
        double[] wait = new double[1000];
        double[] delay = new double[1000];
        double[] departure = new double[1000];
        for (int i = 1; i &lt; 1000; i++)
        {
            arrival[i] = arrival[i - 1] + pro.Exponential(2.0);
            if (arrival[i] &lt; departure[i - 1])
                departure[i] = departure[i] - arrival[i];
            else
                departure[i] = 0;
            service[i] = pro.Uniform((long)1.0,(long)2.0);
            totals += service[i];
            totald += departure[i];
        }
        double averages = totals / 1000;
        double averaged = totald / 1000;
        Console.WriteLine("{0}\n",averages);
        Console.WriteLine("{0}\n", averaged);
        Console.WriteLine("press any key");
        Console.ReadLine();
    }

    public double Random()
    {
        const long A = 48271;
        const long M = 2147483647;
        const long Q = M / A;
        const long R = M % A;
        long t = A * (state % Q) - R * (state / Q);
        if (t &gt; 0)
            state = t;
        else
            state = t + M;
        return ((double)state / M);
    }

    public double Exponential(double u)
    {
        return (-u * Math.Log(1.0 - Random()));
    }

    public double Uniform(long a, long b)
    {
        Program pro = new Program();
        double c = ((double)a + ((double)b - (double)a) * pro.Random());
        return c;
    }
}
</code></pre>

<p>}</p>
