A non-Jew asked Rabbi Joshua ben Korcha, “Do you not claim that God sees into the future?”
“Yes,” he replied.
The man said, “But it is written in your Torah, `And the Lord regretted that He had made people on earth, and His heart was saddened’ ” [Genesis 6:6]; if God knew be forehand that He was going to regret creating humankind, why did He do it?.
Rabbi Joshua asked him: “Has a son ever been born to you?”
“Yes,” the man replied.
“And what did you do [when he was born]?”
He answered, “I rejoiced and made everyone else joyous.”
The rabbi asked, “And did you not know that some day the child would die?”
He answered, “At the time when one should be joyous, be joyous. And when it is time to mourn, mourn.”
The rabbi said, “So, too, with the Holy One, blessed be He.”
——- Genesis Rabbah 27:4