Sit someplace comfortable, take some slow deep breaths , get as relaxed as u can. What has helped me is imagining my thoughts as bubbles floating away from me kind of like when your underwater , and I am just watching them go by, I'm separate from them, they do not control me, they might not even belong to me , don't grab into them, just let them go by . Spend a little time doing this each day, or on a regular basis. Then just go about your day as u normally would. After doing this awhile, I found that my thoughts started to serve me, rather than causing me always to react. Also many many more realizations. It's exciting all the cool stuff there is to learn once you learn to take the mental trash out. Have fun, good luck
If you are having thoughts that seem to come out of nowhere (like something you would never think of by yourself), these are called "intrusive thoughts" and are sometimes a sign that you should see a psychiatrist. Ditto if the thoughts tell you to hurt yourself or others. Ditto if you can actually hear the thoughts and they seem to be coming from outside your head. Sometimes a person will think about something non-stop if it was traumatic or unpleasant. This will sometimes go away on its own, with time. Make sure you get enough sleep.