Random decay is coded in, and works like this: All food stacks start life with a decay value of -24. The negative value then ticks towards 0. Once it reaches 0, the very first tick of decay on the food item is random and based on a function of it's weight. This usually results in a value ranging from 0 to .5%. This initial tick is the most important one, since decay compounds. So a piece of food that takes an initial tick of .5 will be gone long before a piece of food that takes an initial tick of .1. In this way, you can have several "identical" stacks of food in a container or in inventory, all placed there at the exact same time... and all will have vastly different decay values after a period of time.
Temperature of course plays a role in decay rate, by way of being part of the calculation of the environmental decay factor, which is multiplied along with all with other decay factors, such as being cooked, being in a vessel, salted, dried, smoked, preserving etc, when determining the decay amount for each tick. Rain once had an effect on decay as well, but they removed that feature soon after introducing it...
As far as I've observed, everything is working exactly as it's was coded to, and apart from that one bug, as the devs intended it to be...