RNG and time(NULL) vs time(0)

is there another/better way to generate random numbers aside from:
1
2
srand(time(NULL));
x = rand();

that is comprehensible enough for a beginner?

also, what's the difference between using time(NULL) and time(0) in srand()?
Is anything wrong with sradn(time(0))?
NULL is 0. There is no difference between them.
rand() doesn't generate random numbers. It generates PSEUDO-random numbers. Computers are not actually able to generate real random numbers, they can only generate sequences of values that seem random. Quality of this pseudo-randomness depends on the algorithm used. rand() uses very simple algorithm thus it is fast, but generates a poor quality sequence where dependencies between elements of the sequence can be easily found. Nevertheless, for many cases (like simple games, or whatever a beginner could make) it is sufficient. It is not sufficient for example in cryptography, where it is critical to have the highest possible quality of a pseudo-random sequence.

As for your second question, in C++ NULL is defined to 0, so go figure the difference.
Last edited on
Topic archived. No new replies allowed.