Comment on The random number generator of DOOMparentComments−paulannesley11yPresumably they were optimizing for CPU cycles rather than RAM, and the 256 bytes that it does consume isn't much in the scheme of a game like Doom.This must be pretty fast (and compact) code: rndindex = (rndindex+1)&0xff; return rndtable[rndindex];The example C code at https://en.wikipedia.org/wiki/Linear_feedback_shift_register looks like it would compile to more bytes, and require more CPU cycles to execute.Based on https://en.wikipedia.org/wiki/Linear_congruential_generator it seems LCGs also micro-optimize for memory rather than CPU performance.Doom was probably squeezing every last cycle out of 386 @ 25 MHz machines to render frames, but they did have at least 4MB–8MB RAM; 256 bytes seems a good trade-off.
Comments
Presumably they were optimizing for CPU cycles rather than RAM, and the 256 bytes that it does consume isn't much in the scheme of a game like Doom.
This must be pretty fast (and compact) code: rndindex = (rndindex+1)&0xff; return rndtable[rndindex];
The example C code at https://en.wikipedia.org/wiki/Linear_feedback_shift_register looks like it would compile to more bytes, and require more CPU cycles to execute.
Based on https://en.wikipedia.org/wiki/Linear_congruential_generator it seems LCGs also micro-optimize for memory rather than CPU performance.
Doom was probably squeezing every last cycle out of 386 @ 25 MHz machines to render frames, but they did have at least 4MB–8MB RAM; 256 bytes seems a good trade-off.