Adak, I agree it is enough for this exact program. However, in the context of the title of this thread, "2-d monte carlo integration help", rand() is not good enough.

Traditionally RAND_MAX has been very small, typically 32767. Regardless of its period (the length of the sequence of numbers it generates), you can have at most (RAND_MAX+1)^{2}unique random 2D dart positions. On a typical desktop machine, that takes just seconds, not minutes.

In Linux, RAND_MAX == 2147483647, but the generator is still weak; the dart positions form a quite regular lattice. I also think it generates much fewer than (RAND_MAX+1)^{2}unique 2D points, but I haven't verified that.

While using srand() and rand() is okay for the purposes of an exercise,it is never okay to use it with Monte Carlo stuff, it is simply not random enough. The implementation may work, but it is does not use true random sampling; it'll use some implementation-dependent regular or semi-regular sampling scheme. And that's not Monte Carlo, is it?

Instead of random sampling, using a linear congruential pseudorandom number generator like rand() and random(), leads to a sampling pattern that approaches a uniform lattice as the number of samples increases. This is most evident if you draw the points into a picture, and watch it fill up.

Furthermore, using (double)rand()/(double)RAND_MAX will only give you RAND_MAX+1 unique values -- just 32768 on many non-Linux systems! The smallest nonzero value (double)rand() / ((double)RAND_MAX + 1.0) returns may be as big as 0.00003, and the largest 0.99997. In other words, less than five significant digits..

The Xorshift alternative I showed in this thread does not suffer from these issues at all, and the prng_one() yields all doubles within [0, 1), about eighteen significant digits per value.

To OP:

While I understand this is just for an exercise, it is very important to realize the impact a poor random number generator has on Monte Carlo and other random-number based computations. It is very common, and very easy to just overlook that, andassumethe results are good. Most often the result itself is okay, but the error bars obtained from the sampling statistics may be completely bogus, wonkified by the non-random random number generator used.

In this particular exercise you don't need to use random sampling; a regular sampling will give you the best answer anyway. The reason why should be obvious, right? Because of that, Adak is absolutely correct: rand() will work just fine for this program.

I apologize for harping about this so much; I'll try and be quiet now.