Contingency is a tricky business. And not just in theology. Science must deal with questions of contingency, too. And some scientists answer the question wrongly, especially about human free will (which isn’t explicitly discussed here).
 FROM what has been said we may gather that the divine will does not exclude contingency, nor impose absolute necessity on things…
 Moreover. God wills the good of the universe the more especially than any particular good, according as the likeness of His goodness is more completely found therein. Now the completeness of the universe demands that some things should be contingent, else not all the degrees of being would be contained in the universe. Therefore God wills some things to be contingent.
 Again. The good of the universe consists in a certain order, as stated in 11 Metaph.[Aristotle] Now the order of the universe requires that certain causes be changeable; since bodies belong to the perfection of the universe and they move not unless they be moved. Now from a changeable cause contingent effects follow: since the effect cannot have more stable being than the cause. Hence we find that, though the remote cause be necessary, yet if the proximate cause be contingent, the effect is contingent. This is evidenced by what happens with the lower bodies: for they are contingent on account of the contingency of their proximate causes, although their remote causes, which are the heavenly movements, are necessary. Therefore God wills some things to happen contingently.
 Further. Necessity by supposition in a cause cannot argue absolute necessity in its effect. Now God wills something in the creature not of absolute necessity, but only of necessity by supposition, as we have proved. Wherefore from the divine will we cannot argue absolute necessity in creatures. Now this alone excludes contingency, since even contingents that are indifferent to either of two alternatives become necessary by supposition: thus it is necessary that Socrates be moved if he runs. Therefore the divine will does not exclude contingency from the things willed.
 Hence it does not follow, if God wills a thing, that it happens of necessity, but that this conditional proposition is true and necessary, If God wills a thing, it will be: and yet the consequence is not necessary.
Notes How to separate secondary from primary causation? If God is responsible for creating—here-and-now, at each and every moment, and not (just) in some distant past—the entirety of the physical universe (all that is), and God is the primary cause of everything (remember Chapter 13?), the cause without which nothing else could start, how could there be contingency? Contingency means a thing that has changed or happened that didn’t have to.
Aquinas talks about plain-old necessity, by which he means absolute necessity, and suppositional, which is to say, hypothetical, necessity. It is suppositionally necessary that Socrates is moved but only if he walks, runs, or is pushed. Socrates moving is a conditional or local and not a universal truth. Things which are absolutely necessary are so no matter what, but things that are suppositionally necessary are only true if they are. Which sounds funny and is a longer way to state contingency.
Here’s an analogy, and like all analogies it suffers from being absolutely wrong. Air hockey. You hit a plastic puck and there she goes in a contingent direction. But that puck is all the while being held up by a “primary” cause from a deeper level. Your whacking it and its hitting the walls etc. are secondary causes. But those secondary causes are non-starters without the “primary” cause of the puck being held in creation, i.e. in the air. No air blowing and the puck won’t move (unless you strike it hard, which is where the analogy breaks, unless you assume your strength is limited).
And so God, using his Word, is holding everything up like the air on the hockey table, and everything then acts by its powers, which is where contingency arises. God could certainly shuffle the puck along, and might even do so on special occasions (say, miracles), but it would seem He is content to let things act as they will. Hence science is possible. But science does itself a disservice when it fails to recognize the base or true science is God’s will. At some point science must cease and theology must begin.