How to get rid of bad thoughts?

How to get rid of bad thoughts?

All day long we have unwanted thoughts in our mind. Where do they come from and how can I block them and/or get rid of them?