A pseudo-random generator is an engine that produces numbers that look almost random. However, they are completely deterministic. In other words, given the seed x0
, they are created by repeatedly applying some injective function to x0
, call it f(x0)
, so f^m(x0)
very different from f^{m-1}(x0)
or f^{m+1}(x0)
, where the designation f^m
denotes the functional composition m
times. In other words, f(x)
has huge jumps, almost uncorrelated with the previous ones.
If you use sradnd(time)
several times per second, you can get the same seed, since the clock is not as fast as you can imagine. Thus, the resulting sequence of random numbers will be the same. And this can be a (huge) problem, especially in cryptographic applications (in any case, in the latter case, people buy good number generators based on real-time physical processes, such as the temperature difference in atmospheric data, etc. or, recently , for measuring quantum bits, for example, the imposition of polarized photons, the latter being really random if quantum mechanics is correct.)
There are other serious problems with rand
. One of them is that the distribution is biased. See http://eternallyconfuzzled.com/arts/jsw_art_rand.aspx for a discussion, although I remember that I saw something similar on SO, although I cannot find it now.
If you plan to use it in cryptographic applications, just don't do it. Use <random>
and a serious random engine like Mersene twister std::mt19937
in combination with std::random_device
If you generate a random number generator twice using srand
and get different seeds, then you will get two sequences that will be completely different. This may be satisfactory to you. However, each sequence alone will not be a good random distribution due to the problems mentioned above. On the other hand, if you use too much time for your rng, you will get the same seed, and THIS IS BAD, since you will generate the same numbers again and again.
PS: in the comments you can see that pseudo-numbers depend on the seed, and this is bad. This is a definition of pseudo-numbers, and itβs not so bad because it allows you to repeat numerical experiments with the same sequence. The idea is that every other seed should produce a sequence of (almost) random numbers different from the previous sequence (technically you cannot distinguish them from an ideal random sequence).