If I seed a random number in main() with srand(time(NULL)) and generate random numbers in other functions with rand(), will the numbers I generate still be based off the seeded value, thus maintaining true randomness?
There's a bit of a rumor going around that rand isn't exactly random (and by that I mean there seems to be a pattern to it), but those are just conspiracy theories fueled by odd compiler glitches.
There's a bit of a rumor going around that rand isn't exactly random (and by that I mean there seems to be a pattern to it), but those are just conspiracy theories fueled by odd compiler glitches.
Of course there's a pattern to it... it's a PRNG. The 'P' standing for "pseudo".
There's a bit of a rumor going around that rand isn't exactly random (and by that I mean there seems to be a pattern to it), but those are just conspiracy theories fueled by odd compiler glitches.
Im actually having a hard time telling if theres some trolling in there :D Its not just a rumor, its a fact that it is not true randomness. It does have a pattern to it. for example, if you like open and closes the compiler all the time fast, it will increase by around 7 (depending on how fast you open it), I think its becuase its dictated by time obviously duh, becuase of the time(NULL) thing.
Well of course there's that, but I mean an obvious pattern. Some people report the first random generated number is ALWAYS divisible by 7 (which isn't true for me). Others say that if you give rand() a number that's divisible by 7 it will only ever give you 6 and 13 (which is an Xcode glitch but it hasn't happened to me in a very long time).
I don't see how anyone would figure out a pattern, considering the random value you get from rand() with srand() is based off an ever changing seed value(time itself).
I don't see how anyone would figure out a pattern, considering the random value you get from rand() with srand() is based off an ever changing seed value(time itself).
it will produce different patterns for different seeds.
but if you and i use the same seed, our sequence will be same! its not a characteristics of a "true random" number.
put it alternately: if i know your seed i can predict your whole sequence!
while, "true random" number sequences are impossible to predict/calculate.
@Peter87
Do you mean in programming or life in general? If you mean in programming, well then of course nothing is truly random, as every process is based off a sequence of instructions. If you meant life in general, well then I think that's a philosophical question, whether rhetorical or not, that no-one can really answer.
Perhaps I should have worded my first post better. When I said 'true randomness', I was really just referring to the seeming randomness you get from seeding time with srand().
I don't see how anyone would figure out a pattern, considering the random value you get from rand() with srand() is based off an ever changing seed value(time itself).
rand() produces a fixed, looping sequence of numbers.
The seed merely chooses a starting point in that sequence.
Once you see the entire sequence, rand() becomes 100% predictable.
This is true of all pRNGs.
Note that not all random number generators are pseudo random number generators. Some actually use external atmospheric noise to produce random numbers and therefore are considered "truly" random.