Yesterday I can through this confusing C code that implements Conway Game of Life . As a pseudo-random generator, it writes code for this:
int pseudoRand = (int) &pseudoRand;
In accordance with the author comments on the program :
This is a large number that should be different for each run, so it works great as a seed.
I'm pretty sure that the behavior here is either defined in the implementation, or undefined. However, I'm not sure why this value will differ from run to run. My understanding of how most OSs work, because of virtual memory, the stack is initialized to the same virtual address every time the program starts, so every time the address should be the same.
Will this code produce different results in different scenarios on most operating systems? Does it depend on the OS? If so, why does the OS map the same program to different virtual addresses each time it starts?
Thanks!
source share