Abu al-Tufayl Amir bin Wathilah said: I heard Abdullah bin Mas'ud (may Allah be pleased with him) say: The wretched one is he who was decreed wretched in his mother's womb, and the fortunate one is he who takes admonition from the state of others. So I went to Hudhayfah bin Asid and said: Are you not astonished at what Ibn Mas'ud says? He asked: What did he say? I said: The wretched one is he who was decreed wretched in his mother's womb, and the fortunate one is he who takes admonition from the state of others. Hudhayfah said: I heard the Messenger of Allah (peace and blessings be upon him) say: "When forty-five nights have passed over the drop of fluid, the angel says: Is it male or female? So Allah, the Mighty and Majestic, decrees and the angel writes it down. Then the angel says: Is it wretched or fortunate? So Allah decrees and the angel writes it down." He said: Then he says: Its provision, its term of life and its deeds? He said: So Allah decrees and the angel writes it down. He said: Then the scroll is rolled up; nothing is added to it and nothing is taken away from it.
Hadith Referenceالمعجم الكبير للطبراني / باب الحاء / 3025