The Deluge is a remarkable story. Its source and inspiration is found in the Epic of Gilgamesh; in that story, the god Shamash sent a flood upon the earth because humanity had become so numerous that their noise was keeping him awake when he wanted to sleep.
The Hebrew writer took a familiar story and instead of a capricious deity, attributed moral reasons to God as the motivation for the story. You have to view it in the larger context of its literary antecedents and within the framework of the Scripture, not just on its own.
And it also stands from other flood myths in other ways. Pyrrha and Deucalion were the last of their race ever to exist. They saw the earth populated by an entire new race of humans with no relationship to the old one. God instead is depicted as maintaining a relationship with humanity and extending mercy on the righteous, appointing them to repopulate the earth in an echo of the Eden story.