Abdullah bin Masud used to say, "The wretched one is he who was made wretched while still in his mother's womb, and the fortunate one is he who takes warning from the example of others."A man went to one of the companions of the Messenger of Allah ﷺ named Huzaifa bin Usayd al-Ghifari and reported to him this saying of Ibn Masud.Huzaifa asked, "How can a man be made wretched without having done any deed?"The man said to him, "Are you surprised at that?"Huzaifa replied, "Indeed, I heard the Messenger of Allah ﷺ say, 'When forty-two nights have passed over the drop of fluid, Allah sends an angel to it who shapes it and forms its hearing, sight, skin, flesh, and bones. Then the angel asks, "My Lord, is it male or female?" and your Lord decrees what He wills and the angel records it. Then he asks, "My Lord, what is its lifespan?" and your Lord says what He wills and the angel records it. Then he asks, "My Lord, what is its provision?" and your Lord decrees what He wills and the angel records it. Then the angel departs with the scroll in his hand, adding nothing to what he was commanded and omitting nothing from it.'"
أنه عبد الله بن مسعود يقول: سمع الشقي من شقى في بطن أمه والسعيد من وعظ بغيره. فأتى رجلا من أصحاب رسول الله ﷺ يقال له: حذيفة بن أسيد الغفاري. فحدثه بذلك من قول ابن مسعود، فقال: وكيف يشقى رجل بغير عمل؟ فقال له الرجل: أتعجب من ذلك؟ فإني سمعت رسول الله ﷺ يقول: إذا مر بالنطفة اثنتان وأربعون ليلة بعث الله إليها ملكا فصورها، وخلق سمعها وبصرها وجلدها ولحمها وعظامها ثم قال: يا رب أذكر أم أنثى؟ فيقضى ربك ما شاء، ويكتب الملك. ثم يقول: يا رب أجله؟ فيقول ربك ما شاء، ويكتب الملك. ثم يقول: يا رب رزقه؟ فيقضى ربك ما شاء، ويكتب الملك. ثم يخرج الملك بالصحيفة في يده فلا يزيد على ما أمر ولا ينقص.
Muslim narrated it in Qadar (2645) via Ibn Wahb, from Amr bin Harith and Ibn Jurayj, both of them from Abu Zubayr, with the same wording. It is also found in Kitab al-Qadar by Ibn Wahb (31) through this same route, and there are other routes for it as well.