Having bad thoughts or random thoughts during prayer has nothing to do with the acceptance of your prayer; rather they may cause your reward to increase due to the extra effort you do to ignore them. Once you start your prayer, go on and pay no attention to whatever thoughts come to you, no matter how bad or ugly they. Stopping your prayer will not solve the problem but aggravates it. In addition, stopping the obligatory prayer without proper excuse is forbidden. We know that this is so difficult, but you have to try your best. The thoughts may seem incontrollable and therefore you have to find a solution for them.
In conclusion we remind you with the prophetic advice: “know that victory comes with patience; relief with distress; and with hardship comes easiness”. You will find solace in this hadith “No fatigue, nor disease, nor anxiety, nor sadness, nor hurt, nor distress befalls a Muslim, even if it were the prick he receives from a thorn, but that Allah expiates some of his sins for that.”