4 ms·
Since we're bikeshedding... >Yes, they could have used rand() with an appropriate srand(seed) rand() is shared across the whole OS, so another program calling
by xsmasher 12y ago
Since we're bikeshedding...
>Yes, they could have used rand() with an appropriate srand(seed)
rand() is shared across the whole OS, so another program calling rand() could make you skip a number; or another program could reseed rand. Then you've lost determinism.
Even if that weren't the case, you don't want you FX system to call rand() and "steal" the next number that that AI system was expecting.
With Doom's table, each system can keep a separate index into the table; now calling getRand(myIndex++) from one system doesn't interfere with other systems.
- Arnavion 12y agorand() is per-process and not shared across the OS.
- xsmasher 12y agoI stand corrected. My point about different systems still stands.
- deathanatos 12y ago> rand() is shared across the whole OS, so another program calling rand() could make you skip a number; or another program could reseed rand. Then you've lost determinism. Is there actually any implementation of rand that does this? I feel like this would be a buggy implementation, or at the very least, goes against the spirit of the standard, > If srand is then called with the same seed value, the sequence of pseudo-random numbers shall be repeated. If rand is called before any calls to srand have been made, the same sequence shall be generated as when srand is first called with a seed value of 1. > The implementation shall behave as if no library function calls the rand function.
- xsmasher 12y agoI stand corrected, thanks.