What is the reason that G-d brought rain during 40 days in the mabul; could G-d not do it a second?! Of course He could. So what's the explanation for this duration of 40 days?
Rashi to Genesis 7:4 explains that it's because of their sin of adultery:
ארבעים יום. כְּנֶגֶד יְצִירַת הַוָּלָד, שֶׁקִּלְקְלוּ לְהַטְרִיחַ לְיוֹצְרָם לָצוּר צוּרַת מַמְזֵרִים
"Forty days" – corresponding to the formation of the fetus, for their sins troubled their Creator to form the form of children of illicit relations.
Rashi here refers to a Talmudic tradition that the formation of the fetus is at forty days.