When you wonder what a library function does, you should look it up. Get into the habit of reading the language or library's documentation. This can be more or less helpful depending on the quality of the documentation, but when the quality is good, that's your problem solved.
In this particular case, the reference documentation is admittedly pretty hard to follow. Searching for “
set.seed R” on the web finds some good articles, e.g. 1 2 3 4.
That being said, let me answer the on-topic aspect of the question, which is how seeding the random generator (which is what
set.seed does) relates to the Monte-Carlo method.
A Monte Carlo method is an algorithm that uses random sampling to make approximate calculations. It's used when doing the full calculation with all the data would involve such a high volume of data that the calculation would be impossible in practice. So instead we do the calculation with a small subset of the data. This can only work if the subset is representative of the data.
To get a representative subset, we take data points at random. Statistically, in most physical systems, even a moderate amount of data points (e.g. thousands out of billions) are enough to get reasonably accurate results.
For programming, the downside of a random selection is that if you run the program twice, you'll get different results. The results should be approximately the same if the Monte Carlo method is suitable for the problem that's being solved, but they won't be identical. For example, you can't double-check someone else's calculation.
So instead of using an actual random selection, the program uses a pseudorandom selection. A pseudorandom generator (PRNG) is a source of numbers that is reproducible, but when you only look at the numbers, they're indistinguishable from a truly random source. (There are different levels of quality to the indistinguishability — for example cryptography requires a higher level of indistinguishability than Monte Carlo simulations.) The seed of a PRNG is an input to the generator, such that if you run the PRNG twice with the same seed, you get the same outputs. But if you run different seeds, you get different, independent outputs. A pseudorandom generator works just as well as a random generator because it's independent (in the probabilistic sense, but I'm not going to formalize this) from anything else, including the phenomenon you're modelling. (It's also independent from the same PRNG with a different seed.)
There is no significance to the value 5678. Any number would do (at least any number within the permissible range for that particular library function). You can use a different value and you'll get results that are different, but statistically equally representative of the phenomenon.