The Prophet ﷺ said, "Allah has assigned to the womb an angel who says, 'My Lord, a drop of fluid. My Lord, a clinging clot. My Lord, a lump of flesh.' When Allah wills to complete his creation, the angel asks, 'Male or female? Wretched or blessed? What is his provision? What is his lifespan?' All of this is then written while he is in his mother's womb."
أن النبي ﷺ قال: إن الله عز وجل وكل بالرحم ملكا يقول: يا رب نطفة، يا رب علقة يا رب مضغة، فإذا أراد أن يقضي خلقه قال: أذكر أم أنثى؟ شقي أم سعيد؟ فما الرزق والأجل؟ فيكتب بطن أمه.