pRNGs are typically mathematical equations. A simple example would be:
OUT = (X * IN) + Y;
Where 'X' and 'Y' are constants (typically prime numbers).
'OUT' is both
- your random number
and
- 'IN' for the next time the formula is run.
The "seed" is just the initial value for 'IN'.
Of course this is a simplistic example. More complex RNGs will work differently and may require larger/more seeds. But the concept is more or less the same.
rand uses the previous random number to generate a next one, if you set the seed to a value, and then call rand, youll get a number. If you seed it again with the same value, youll get the same number again.
its the reason people usually srand(time(NULL)), to set the seed to the current time, wich is always different, so that a program will always have different random numbers
(if you dont srand(), and output rand() 10 times, your program will output the same 10 numbers everytime)
wow that is interesting I never knew that before about the input being the output from the previous iteration. I just had always assumed that srand() took the seed and generated a series based on some propriety mathematical formula, and kept track of the index of the series inside a private variable that was incremented each time rand() was called. I guess it makes more sense the way you describe though, but would it be possible the other way too? Also, how is it possible to srand(seed1, seed2, seed3) as disch saids... can you specify an unspecified amount of parameters?
Of course this is a simplistic example. More complex RNGs will work differently and may require larger/more seeds. But the concept is more or less the same.
I wasn't describing rand() in particular, I was describing the general overall concept of how RNGs work.
The output may not be used as the input directly, but it is used to affect the next input somehow.
wtf wrote:
Also, how is it possible to srand(seed1, seed2, seed3) as disch saids
I never said this.
What I said is that other RNGs might take larger/more seeds. Again I was speaking of RNGs in general, not rand(). rand() is just one RNG. There are tons of others.
In general the seed needs to be at least as big as the period of the RNG. So if you have an RNG with a period of 2^128, then it needs to have a seed that's at least 2^128.
rand() doesn't have that large of a period, so its seed is smaller.