generating stochastic coloured noise for many oscillators I have a system of n oscillators which oscillate with time. To each of these oscillators I am adding a fluctuating coloured noise term with a different seed for each oscillator. Here is my code for the generation of this noise:
#include &lt;math.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stddef.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;iostream&gt;
#include &lt;random&gt;

using namespace std;

double dt = 0.01;

static normal_distribution&lt;double&gt; n_dist(0 , sqrt(dt));
static random_device rd;
static default_random_engine generator(rd());

static double dW ( double dt ) {
    return n_dist(generator);
}

void exp_noise(double gamma, int steps, double c_sigma, float X[])
{
    X[0] = 1;
     
    for (int i = 0; i &lt; steps; i++ ){
        X[i+1] = (1 - gamma) * X[i] + c_sigma * sqrt(2*gamma) * dW(1);
    }
}

int main()
{
    int n = 256;
    constexpr int steps = 1000;

    float X[n*steps];
    for( int i=0 ; i&lt;n ; ++i ){
        float X_i[steps];
        memset(X_i, 0.0, sizeof X_i);
        exp_noise(0.4, steps, 1, X_i);
        for( int j=0 ; j&lt;steps ; ++j ){cout &lt;&lt; X_i[j] &lt;&lt; '\n';}
        memcpy( X + i*steps, X_i, sizeof( X_i ) );
    }

    cout &lt;&lt; &quot;total vector is&quot; &lt;&lt; '\n';
    for( int i=0 ; i&lt;n*steps ; ++i ){cout &lt;&lt; X[i] &lt;&lt; '\n';}
    
    return 0;
}

Essentially my code is producing something similar to an array of noise for each oscillator, and then appending all of those arrays together. The intention is to apply to above code to my oscillators in the following way.
for (int h = 0; h &lt; steps; ++h){
    for( int i=0 ; i&lt;n ; ++i ){
        oscillator[i] = stoch_runge_kutta( oscillator[i], X[ h + i*steps ], ... )
    }
}

This code seems to work well for a small number of steps. This code unfortunately breaks down however for values of n * steps &gt; 2500000 with a stack overflow error. So my first question would be whether the code can be made more stable to the value of n*steps with some minor changes, or whether I need to change everything by using vectors instead? I would also be interested in knowing whether the code would be faster or more elegant if I completely redesigned the code in some other way, for example by not creating an array of arrays, and doing something else instead? How would these things be done? It's not essential, but it's preferable to have the noise as an array so that it can be reused to for other things.
Any help would be greatly appreciated.
#include &lt;math.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stddef.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;iostream&gt;
#include &lt;random&gt;

using namespace std;


Please don't put all the standard identifiers into the global namespace.  Use the C++ versions of the libraries, and qualified names.  If you really must drag some identifiers in (as is often required for argument-dependent lookup), be specific and keep their scope small.
And try not to mix C standard I/O and C++ streams if possible.
#include &lt;cmath&gt;
#include &lt;cstddef&gt;
#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;random&gt;