The question "How is loot generated" rings far and wide, and with permission I have created a visual guide on how loot in general is generated, this excludes certain things, but it should give a good idea on how it works:



What is excluded from this image is some deeper workings, and also quest loot generation.

Quest loot works slightly different in that once you have a quest, a keyword triggers and monsters sharing this keyword get an extra loot drop, specifically for the quest item. (this is also why you can get quest items to drop before you are on the right step, as it can only be triggered by having the quest, not by being on a certain step)

Once you open the loot window, a number is generated in between certain values (60-80 for example) and another number is generated at the same time.

This first value is what can be seen as the limit, the second number is your personal roll, if this is above the first number, it triggers the quest loot to appear in the monster's loot window, if it is below it will return nothing.
___
Again, this is a generalization of the system and does not represent it 100% but it's the basics.

(apologies for any typos present in the image)