And it shall come to pass, when I cause clouds to come upon the earth, that the rainbow will appear in the cloud. [Noach 9:14]
When does God show a rainbow?
Rashi: When it arises in His mind to bring darkness and destruction to the world.
Bachaye: The rainbow does not appear on every cloudy day or on any occasion that it rains, but only when the generation deserves destruction, to indicate that God is guarding His promise.