Abdullah bin Masud relates that Allah’s Messenger (may Allah bless and greet him) who is the most truthful (of human beings) and his being truthful (is a fact) said: “Verily, your creation is on this wise. The constituents of one of you are collected for forty days in his mother’s womb in the form of blood, after which it becomes a clot of blood in another period of forty days. Then it becomes a lump of flesh and forty days later Allah sends His angel to it with instructions concerning four things, so the angel writes down his livelihood, his death, his deeds, his fortune and misfortune. By Him, besides Whom there is no God, that one among you acts like the people deserving Paradise until between him and Paradise there remains but a distance of cubit, when suddenly the writing of destiny overcomes him and he begins to acts like the denizens of Hell, and thus enters Hell; and another one acts in the way of the denizens of Hell, until there remains between him and Hell a distance of a cubit that the writing of destiny overcomes him and then he begins to act like the people of Paradise and enters Paradise.
This does not mean that man is a mere puppet in the hands of destiny. Man is capable of doing both good and evil. God knows man’s destiny for certain which course he/she would adopt on such and such occasions, but he is not forced to act in a specific way. Nothing can be said about one’s ultimate end during one’s life. A wicked person can get into Paradise after sincere repentance and changing his pattern of behaviour just on the eve of death. Similarly, a good and pious person can get into Hell by committing a grave sin and taking to evil course just at the end of his life. Instead of throwing our lot into the hands of destiny, we ought to strive our best to remain pious all through our life and pray for a good end thereof.