Everything occurs according to preordainment and according to what has been decreed. Such is the belief of Muslims, the followers of Muhammad (Blessings and Peace be upon him). And nothing happens in the Universe except through Allah's Knowledge, Permission, and Divine Plan.
(No calamity befalls on the earth or in yourselves but is inscribed in the Book of Decrees ---- (Al-Lauh al-Mahfuz), before We bring it into existence, Verily that is easy for Allah.) (Qur'an 57: 22)
(Verily, We have created all things with Qadar [Divine Preordainments of all things before their creation, as written in the Book of Decrees Al-Lauh al-Mahfuz.) (Quran 54: 49)
(And certainly, we shall test you with something of fear hunger loss of wealth, lives and fruits, but give glad tidings to the patient ones.)
(Quran 2: 155)
And in a hadith, the Prophet (bpuh) said:
"Wonderful is the affair of the believer! His affairs in their entirety are good for him: if good befalls him. he is thankful, and that is good for him. And if harm befalls him, he is patient, and that is good for him. And this (prosperous state of being) is only for the believer."
In an authentic hadith, the Prophet (bpuh) said:
"If you ask, then ask of Allah, and if you seek help, then seek it from Allah. And know that if the whole of the nation were to rally together in order to bring benefit to you in anything, they would not benefit you except with that which Allah has written for you. And if they were to gather together in order to inflict harm upon you with something, they would not harm you except with that which Allah has written upon you. The pens have been raised and the pages have dried."
The Prophet (Blessings and Peace be upon him) also said:
"And know that what has befallen you was not going to miss you, and that which missed you was not meant to befall you."
In another authentic hadith, the Prophet (bpuh) said:
"Strive for that which will benefit you, seek help from Allah, do not be weak, and do not say: If I had done such and such, the situation would be such and such. But say:
Allah has decreed and what He wishes, He does."
And in another authentic hadith, the Prophet (bpuh) said:
"Eve1y matter that Allah decrees for His slave is better for him."
Shaykh al-Islam Ibn Taymiyah was asked about sin: Is it good for someone? He said:
"Yes, with the condition that it is followed by being remorseful and repentant, by seeking forgiveness, and by being sincerely moved (to submission) on the inside."
Allah, the Exalted, says:
(And it may be that you dislike a thing, which is good for you and that you like a thing, which is bad for you. Allah knows but you do not know?
(Quran 2: 216)