Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
GarrettChan

How RNG works for Super Shotgun in Classic Doom?

Recommended Posts

On 7/13/2017 at 6:10 PM, Graf Zahl said:

 

Easier, yes, but as has been said, such an unbalanced table ultimately yields biased results. You can twist it as much as you like - the entire method to calculate random numbers here is utter garbage. I'm pretty sure the only reason for this implementation was to avoid doing some research.

 

The RNG is just another element where id went cheap instead of well-defined. You do not need a near-'perfect' RNG like ZDoom does, but any simple algorithm that can be seeded for different but well-defined sequences would have been better than a 256-entry byte table.

 

It's not garbage to me. For the requirements, the id implementation is actually spot on. It "feels" just random enough, and it's blindingly fast. A minimal "proper" seeded RNG requires seed storage, a multiply, and maybe an addition and a division (mod). id's code? INC, AND, and a memory access. Granted, it's output sucks for general use, but for controlling monster moves, when to fire, damage amounts? It's plenty sufficient. It's another case of id doing a good job balancing factors empirically to satisfy the requirements optimally.

 

In hectic scenes with lots of monsters and missiles, P_Random gets called hundreds of times per tic. On the target 486, a better RNG might be a significant bottleneck. Absolutely everything had to be done as quickly as possible. Nowadays we can afford to do a bit better. But, I'd bet that, for it's original uses, you'd be hard-pressed to even notice the difference in randomness, except for contrived tests, like shooting a wall, or initial deathmatch spot choice.

 

id made a lot of choices that cause problems for PWADs, but work perfectly on the original levels, which is all they really had to do. With the release of the source, it's up to us to correct the rest of it :)

Share this post


Link to post
4 hours ago, insertwackynamehere said:

Not having ever poured over the source like some of you guys and basing this off the examples I see in the thread, I see ID doing a lot of things with random numbers that are not great. Having a table of predefined random numbers is fine I guess for a game where they don't need to really be secret, but taking those numbers and using modulo or AND to clamp the entropy down or whatever probably skews distribution a bunch. If the code had to be cryptographically secure (which it doesn't) that would be a pretty bad thing to mess up. Even so, I'm sure it contributes to bias somehow within the game although I only know this stuff from the distance, I'm far from an expert.

The id RNG's AND (used as a fast modulo) does not clamp any entrophy - the range of numbers is hard-coded to 8-bits, and the numbers are not distributed evenly. Some numbers are duplicated (and even triplicated), and some numbers are missed altogether. So some numbers within the range will never be produced, and some others occur more frequently. But nowhere does the source use these numbers as an index into an array - they are just treated as magnitudes, so this does not really cause a problem. The closest they come to depending on the exact values is in which monster the boss spawner will spawn, but, even here, they check for a range of numbers, not an exact number, so it works ok.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×