Just about all teenage guys in puberty get spontaneous boners like you do. Its completely normal, and they're mostly caused by the rapid increase of testosterone in your system, and your brain isn't used to it yet, and uncontrolled erections happen. Unfortunately, there's nothing you can do to prevent them, so the best policy is to try to hide them as best you can. Wear baggy clothes for example. When I started getting spontaneous boners at about 14, all I wore were baggy sweatshirts during school, for most of my high school years, to help hide my constant erections. :blush:
Don't worry, they will start to happen less often, and you will eventually gain full control (or mostly) of your erections as you get older and finish puberty near your late teens. But you will have several years of these spontaneous erections to get through first.