Let us assume that God is the director of a great cosmic drama. As grand director, He chooses to let those starring in the cosmic play, follow the script according to their agent-causal powers. Now the director knows both the AB INITIO of the play and the TERMINUS (Isa 46:10); however, the events that transpire in the middle are not tightly scripted and thus occur spontaneously. But, since He is the director, God can make adjustments here and there during the play in order to ensure that the TERMINUS finishes according to His liking.
Furthermore, being the superb director that He is, God knows that a number of "actors" will adhere closely to the script: He knows the thoughts and intentions of the human heart (1 Sam 16:7). Nevertheless, those who refuse to act in harmony with the script will not thwart God's drama since He remains omnipotent (or almighty), qualitatively infinite and omniscient.