(Genesis 6:9:) "These are the generations [of Noah; Noah was a righteous man, perfect in his generations]." What is the meaning of "in his generations"? There are those who expound it to praise, and there are those who expound it to disgrace. "A righteous man" — in his generations, but not in other generations. A parable; to what is the matter comparable? If a person places a silver sela among [a hundred] copper selas, that silver one appears beautiful. So too did Noah appear righteous in the generation of the Flood. How do some expound it to praise? It is comparable to a young woman who dwelt in a market of harlots and yet remained virtuous (kasher); had she been in a market of the virtuous (kesherot), how much more so. A parable to a jar of balsam that was placed in a grave, and its fragrance was good; had it been in a house, how much more so.
Noah Righteous in His Generations - Silver, Balsam, and the Virtuous Maiden
Midrash Tanchuma Buber, Noach 6:1
אלה תולדות [נח נח איש צדיק תמים היה בדורותיו]. מהו בדורותיו, יש דורשין לשבח, ויש דורשין לגנאי, צדיק בדורותיו ולא בדורות אחרים, משל למה הדבר דומה, אם יתן אדם סלע של כסף בתוך [מאה] סלעים של נחשת, אותה של כסף נראית נאה, כך היה נח נראה צדיק בדור המבול, יש דורשין אותו לשבח כיצד, לנערה שהיתה שרויה בשוק של זונות והיתה כשרה, אלו היתה בשוק הכשרות על אחת כמה וכמה, משל לחבית של אפרסמון שהיתה נתונה בקבר והייתה ריחה טוב, אילו היתה בבית על אחת כמה וכמה.