Rabbi Tachanah said: Noah made the ark during fifty-two years, so that they should repent of their ways. But they did not repent. Whilst yet the Flood had not come, the unclean (animals) were more numerous than the clean (animals). But when the waters of the Flood came, and the Holy One, blessed be He, wished to increase the clean and to diminish the unclean (animals), He called to Noah and said to him: Take to thee into the ark of all clean beasts seven and seven, the male and his female; and of the unclean beasts two and two, the male and his female, as it is said, "Of every || clean beast thou shalt take to thee seven and seven, the male and his female; and of the beasts that are not clean two, the male and his female" (Gen. 7:2).
The Flood and the Ark
Pirkei DeRabbi Eliezer 23:3