Is the contents of a Mann Co. Supply Crate set before it is opened?
Solution 1:
Source
Though the notion and concept of a crate suggests that the contents should be predetermined, Robin Walker has confirmed the mechanics are such that item drop is determined at the point of opening the crate; moreover, items are not mapped to crates and thus there is no distinction to be made between two crates of identical series.
Solution 2:
There's no way of knowing what's in the crate before opening, other than just what it's possible for the crate to contain. I would guess that Valve just generates what's in it when you open it so they don't have to keep track of what's in hundreds of thousands of crates for no reason, but there's no way to know how they do it. Opening crates is just a gamble.