Inner product of random floats written to file
If you're going to use C++11, you should firstly look at throwing out rand, and using the newer features found in &lt;random&gt;. The setup is a bit more complex, but the distributions are generally much better statistically. Also, instead of generating numbers one at a time, we're going to generate them in a batch:

template &lt;typename Cont = std::vector&lt;double&gt;&gt;
Cont generate_rand(std::size_t n)
{
    Cont results;
    results.reserve(n);

    std::random_device rd;
    std::mt19937 generator(rd());
    std::uniform_real_distribution&lt;&gt; dist;
    auto random = [&amp;]() { return dist(generator); };
    std::generate_n(std::back_inserter(results), n, random);
    return results;
}


With this, we can generate a set of random values into a vector:

// Read into num however many values we want to generate from args
auto vec = generate_rand(num);


Working with an actual matrix is a bit easier, so let's generate that (instead of an n * n length vector):

std::vector&lt;std::vector&lt;double&gt;&gt; matrix;
for(auto i = 0; i &lt; num; ++i) {
    matrix.emplace_back(generate_rand(num));
}


Something to hold our results, with the size correctly reserved:

std::vector&lt;double&gt; result;
result.reserve(num);


The algorithm library already has a function that will do what you want: std::inner_product:

for(auto it = matrix.begin(); it != matrix.end(); ++it) {
    auto v = std::inner_product(std::begin(vec), std::end(vec), std::begin(*it), 0.0);
    result.push_back(v);
}


Alternately, this is the place where a library like Eigen comes in really handy; with the correct includes, this can be written as follows:

#include &lt;Eigen/Core&gt;

typedef Eigen::MatrixXd Dynamic2d;

int main()
{
    // Initialize num from program args
    auto x = Dynamic2d::Random(num, num);
    auto y = Dynamic2d::Random(1, num);
    auto res = y * x;
}


(Note however that Random gives a range between [-1, 1] when called like this, so you'd need to potentially do a bit of work to get that distribution back to [0, 1]). This is likely to give you the maximum performance, as libraries like Eigen have had a lot of time spent on making them highly efficient.