"And Joktan begot Almodad" and so forth (Genesis 10:26). There is a place named Hazarmaveth [Court of Death], where they eat leeks and wear garments of papyrus and look toward death every day; and Samuel said, they do not even have garments of papyrus. "And their dwelling was from Mesha" (Genesis 10:30): Mesha is death, Media is sick, Elam and the snatchers of the dying, the seacoast is the blue-dye of Babylon, Tyre is the painted blue of the seacoast, between the rivers is like the exile for genealogies, "the mountain of the east" is the mountains of the east. For nine hundred seventy-four generations before the world was created, the Holy One, blessed be He, sat and expounded and searched and tested and refined the whole Torah, and from the day the world was created until that hour, every single word that is of the words of Torah He expounded and searched and tested and refined two hundred forty-eight times, corresponding to the two hundred forty-eight limbs that are in a human being, and afterward He brought it forth from His mouth and fixed it in His Torah, as it is said, "The words of the LORD are pure words" (Psalms 12:7). And every single word that He fixed in the Torah, if it moves from its place even a little, it ruins the whole world. It was in the intent of the Holy One, blessed be He, not to give an opening of the mouth to the beast, but because He gave an opening of the mouth to the serpent, it ruined the whole world. Ten generations from Adam to Noah: it was in the intent of the Holy One, blessed be He, to visit the iniquity of the fathers upon the sons, but He did not visit it; rather, each one made himself king over his wife and over the members of his household, and they had neither fear of kingship nor the measure of punishment, but they ate and drank and were sated and kicked out of their abundance, as it is said, "And they said to God, depart from us" (Job 21:14). Ten generations from Noah to Abraham: it was in the intent of the Holy One, blessed be He, to divide them into seventy languages, but they did not act so; rather, they made themselves all one language and sought to destroy the whole world, as it is said, "And the whole earth was of one language" (Genesis 11:1).
God Refined the Whole Torah Before the World Was Made
Yalkut Shimoni on Torah 62:5
(בראשית י כו) וְיָקְטָן יָלַד אֶת אַלְמוֹדָד. וְגוֹ' מָקוֹם הוּא שֶׁשְּׁמוֹ חֲצַר מָוֶת שֶׁהֵן אוֹכְלִים כְּרִישִׁין וְלוֹבְשִׁין כְּלֵי פַּפְיֵיר וּמְצַפִּין לְמִיתָה בְּכָל יוֹם, וּשְׁמוּאֵל אָמַר, אֲפִילּוּ כְּלֵי פַּפְיֵיר אֵין לָהֶם. (בראשית י ל) וַיְהִי מוֹשָׁבָם מִמֵּשָׁא. מֵשָּׁא מֵיתָה מָדַי חוֹלָה עֵילָם וגוֹנְבֵי גוֹסְסוֹת חֶבֶל יַמָּא תְּכֵלְתָא דְּבָבֶל צוֹר צִיִר תְּכֵלְתָא דְחֶבֶל יַמָּא בֵּין הַנְּהָרוֹת כְּגוֹלָה לְיוֹחֲסִין הַר הַקֶּדֶם טוּרֵי מַדִינְחָא. תְּשַׁע מֵאוֹת וְשִבְעִים וְאַרְבָּעָה דּוֹרוֹת עַד שֶׁלֹּא נִבְרָא הָעוֹלָם יָשַׁב הַקָּדוֹשׁ בָּרוּךְ הוּא וְדָרַשׁ וְחָקַר וּבָחַן וְצֵרֵף אֶת כָּל הַתּוֹרָה כֻּלָּהּ, וּמִיּוֹם שֶׁנִּבְרָא הָעוֹלָם עַד אוֹתָהּ שָׁעָה, וְכָל דָּבָר וְדָבָר שֶׁהוּא מִדִּבְרֵי תּוֹרָה דְּרָשׁוֹ וּחְקָרוֹ וּבְחָנוֹ וְצֵרְפוֹ בְּמָאתַיִם אַרְבָּעִים וּשְׁמוֹנֶה פְּעָמִים כְּנֶגֶד מָאתַיִם אַרְבָּעִים וּשְׁמוֹנָה אֵבָרִים שֶׁבָּאָדָם, וְאַחַר כָּךְ הוֹצִיאוֹ מִתּוֹךְ פִּיו וְּקְבָעוֹ בְּתוֹרָתוֹ, שֶׁנֶּאֱמַר (תהלים יב, ז) אִמְרוֹת ה' אֲמָרוֹת טְהוֹרוֹת וְגוֹ', וְכָל דָּבָר וְדָבָר שֶׁקָּבַע בַּתּוֹרָה אִם זָז מִמְּקוֹמוֹ קִמְעָא קִלְקֵל אֶת הָעוֹלָם כֻּלּוֹ וּבְדַעְתּוֹ שֶׁל הַקָּדוֹשׁ בָּרוּךְ הוּא שֶׁלֹּא לִיתֵּן פִּתְחוֹן פֶּה לִבְהֵמָה וּמִתּוֹךְ שֶׁנָּתַן פִּתְחוֹן פֶּה לַנָּחָשׁ קִלְקֵל אֶת כָּל הָעוֹלָם. עֲשָׂרָה דּוֹרוֹת מֵאָדָם וְעַד נֹחַ, בְּדַעְתּוֹ שֶׁל הַקָּדוֹשׁ בָּרוּךְ הוּא לִפְקֹד עֲוֹן אָבוֹת עַל בָּנִים, וְלֹא פָּקַד, אֶלָּא כָּל אֶחָד וְאֶחָד עֲשָאוֹ מֶלֶךְ עַל אִשְׁתּוֹ וְעַל בְּנֵי בֵּיתוֹ, אֵין לָהֶם לֹא אֵימַת מַלְכוּת וְלֹא מִדַּת פֻּרְעָנוּת, אֶלָּא אוֹכְלִין וְשׁוֹתִין וּשְׁבֵעִין וּבוֹעֲטִין מִתּוֹךְ הַטּוֹבָה, שֶׁנֶּאֱמַר (איוב כא, יד) "וַיֹּאמְרוּ לָאֵל סוּר מִמֶּנּוּ" עֲשָׂרָה דּוֹרוֹת מִנֹּחַ וְעַד אַבְרָהָם בְּדַעְתּוֹ שֶׁל הַקָּדוֹשׁ בָּרוּךְ הוּא לְחַלְּקָם לְשִׁבְעִים לָשׁוֹן, וְהוּא לֹא עָשָׂה כֵן, אֶלָּא עֲשָׂאָן כֻּלָּן לָשׁוֹן אֶחָד וּבִקְּשׁוּ לְהַחֲרִיב אֶת כָּל הָעוֹלָם כֻּלּוֹ, שֶׁנֶּאֱמַר וַיְהִי כָל הָאָרֶץ שָׂפָה אֶחָת.