Hakim al-Umma mujadid Shaykh Mawlana Shah Ashraf ‘Ali Thanawi (Allah have mercy on him) said,
‘None of us can surpass the ranks of the Holy Companions (sahaba). They were also afflicted with such worrisome random thoughts (waswasa) that they approached the Prophet (Allah bless him and give him peace) and said that they felt it was easier to burn and turn to char then to utter them. However, the Prophet (Allah bless him and give him peace) replied;
ذاك صریح الایمان
It is very obvious that there can be no worst random thoughts than that of unbelief (kufr). However, this ruling applies even to it.
If there are such overwhelming random thoughts then one should use the prescription of diverting one’s thoughts towards something else. This something else could even be a worldly matter, like carrot halwa or turnip pickle. Thoroughly occupying one’s thoughts with (the list of) their ingredients, amounts and recipe. Diverting the thoughts in this manner will indeed require effort initially. However, inshaAllah, eventually the power to ward off these worrisome random thoughts will be achieved.’
Basair e Hakim ul-Ummat ra, page 254-5