No matter how we try to avoid bad thinking, it will always come in our minds because of the whispers of the Jinns and of mankind.
“From the evil of the whisperer (devil who whispers evil in the hearts of men) who withdraws (from his whispering in one’s heart after one remembers Allah); who whispers in the breasts of mankind, of Jinn and men.” [The Quran, Surah An-Nas 114:4-6]
Narrated Abu Hurairah (Radiyallahu Anhu – may Allah be pleased with him): The Prophet ﷺ said: “Allah forgives my followers those (evil deeds) their souls may whisper or suggest to them as long as they do not act (on it) or speak.” [Sahih Al-Bukhari, vol. 8, #657]
A believer may be subjected to evil suggestions with which his chest becomes straitened. A Companion said: “O Messenger of Allah! One of us would have some thoughts in his mind that he would rather fall down to earth from the sky than to utter them.” The Prophet said: “That is the pure faith.” [Ahmad and Muslim]
In another version: “When one feels it is terrifying to utter those thoughts, he should say: (الحمد لله الذي رد كيده إلى الوسوسة) “All praise is due to Allah, who reduced the plotting of Shaytan into mere suggestions.” That is to say, having such suggestions along with intensive abhorrence of them and repulsing them from the heart is an expression of pure faith. [The Book of Eemaan, p. 238]