-6

From what I’ve read on the c++ website, the srand function, puts a seed in the rand function, but I don’t really understand what a seed is.

1 Answers1

1

"I don’t really understand what a seed is" - A seed in the context of a Pseudo Random Number Generator (PRNG) is a starting value to use for the generation of the pseudo random sequence.

A PRNG that starts with the same seed will (in most cases) produce the same sequence of random numbers. This is great for replayability of a scenario, but is not generally what you want in production. Usually you want to provide a unique/unpredictable seed to the generator for each instance of the application, so that each run gives a unique stream of pseudo random numbers.

I would recommend using the new random facilities (since C++11) that are available in the random header over srand()/rand() since rand has a very low range and usually also a very low period. The new facilities are much better.

You may also find this talk enlightening: rand() Considered Harmful

The Wikipedia page on pseudo random number generators is also worth a read.

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70