You probably only want to split the random number generator. rand() returns the next pseudo-random number from it of the internal generator. Each time you call rand() , you will get the next number from the internal generator.
srand() however sets the initial conditions for the random number generator. You can think of it as setting up a “starting point” for an internal random number generator (actually it is much more complicated than that, but it is a useful cognitive model).
So, you should call srand(time(0)) exactly once in your application - somewhere near the start. After that, you can call rand() as many times as you want!
but
To answer your real question - the first version does not work, because time() returns the number of seconds from the moment. So, if you call coinToss() several times per second (say, if you want to simulate 100 coin throws), you will constantly sow a random number generator with the same number, thereby resetting its internal state (and thus the next number which you get) every time.
In any case, using time() as a seed for srand() is pretty crappy for this very reason - time() does not alternate very often, but worse, it is predictable. If you know the current time, you can decide what rand() will return. There are many, many examples of the best srand() seeds on the Internet.
Thomi source share