Rasul Allah (sal Allahu alaihi wa sallam) said: “Allah has put an angel in charge of the womb. He says, ‘O Lord, a drop? O Lord, a clot? O Lord, a morsel?’ When Allah desires to complete the creation of the foetus, he says, ‘O Lord, male or female? Wretched or happy? How much provision? How long a lifespan?’ and he writes that for him in his mother’s womb.” [Sahih Bukhari]
This hadith informs us that Allah (subhana wa ta’ala) has charged an angel with the responsibility of the development of foetuses. It is only with Allah’s permission that the angel allows conception to take place. The angel then seeks Allah’s permission to proceed at each stage of the development of the embryo.
The matters of gender, happiness or sadness, Rizq (provision), and lifespan, are decided for a person while they are still in the womb.
That is why we are told not to adopt Haraam means to earn our living because how much we will receive of sustenance is already preordained. Resorting to activities prohibited by Allah (subhana wa ta’ala) will not increase your wealth. One way of looking at it is that what you obtain by Haraam means you would have gotten some other Halaal way. Another way of looking at it is that what you obtain by Haraam means, forcefully trying to increase your Rizq, you will lose in some other way (e.g medical treatment, robbery, etc).
Similarly, this hadith tells us to live our lives as respectable, brave, Muslims. A single day lived like a lion is better than a hundred years lived like a hyena. Even if you got to live for a thousand years you would still die and enter the ocean of the Hereafter. When your time of death cannot be changed by even a second then why compromise your Akhirah for it?
So also, events that will make us happy or sad are written in our destiny. Our test is what our reaction to those events is going to be. Do we thank Allah (subhana wa ta’ala) when something makes us happy or do we become proud and credit ourselves for the good fortune. Similarly, when the going gets tough do we display patience with Allah’s decree or utter words of ingratitude.
We must remember that all of life is a qualification exam for Jannah. The events (questions) are pre-ordained (decided) while our reactions (answers) are in our control.