A seed starts the sequence

C’s `rand()` is a pseudorandom number generator: it uses arithmetic to produce values that look irregular, but its next value is determined by an internal state. Calling `srand(seed)` sets that starting state. Give the generator the same seed, then make the same number of calls, and it produces the same sequence.

If a program never calls `srand()`, the C library behaves as though it had been seeded with `1`. That makes a program’s results repeat from run to run, which can be useful when debugging: the same sequence can reproduce the same behavior. Different C libraries may use different algorithms, however, so a sequence need not match across platforms.

Why predictability matters

A program can turn a `rand()` result into a smaller range—for example, by taking a remainder. But this does not make the generator more random, and some results may occur more often than others when the range does not divide evenly into the generator’s possible values.

More importantly, `rand()` is not designed to protect secrets. If an attacker can infer its state or seed, future outputs may be guessable. That makes it suitable for simple games or repeatable tests, but not for passwords, encryption keys, or security tokens. The same repeatability that helps a programmer recreate a bug can expose a value that was supposed to be unpredictable.