Sometimes I have a "how awful would it be to do XY" moments. Usually something brutal. But it always makes me pay even more attention to not doing that very thing even accidentally because I definitely do not want to break stuff or hurt someone. Yet it makes me a bit nervous. What if I actually decided to do that? Fortunately it never happens when I'm under influence. Do I need help?
As others have said, these sound like typical intrusive thoughts.
The most common intrusive thoughts are, I believe, the "call of the void" ones (also known as "high place phenomenon"). You might be driving down the freeway and think "What if I drove into oncoming traffic?" or standing on a cliff at the end of a hike and think "What if I just walked off the ledge?" There's also some common less-morbid ones, like "What if I kissed my boss right now?" or "I just want to scream in the middle of this board meeting for no reason." Your immediate reaction should usually be to dismiss the thought as disturbing and move on with your life. If you find this dismissal to be difficult... that's when it can be worth checking out with a psychologist.
One hypothesis [0] for this phenomenon is that it is actually a post-fact reconstruction your brain is doing. Really, it's that your subconscious was uncomfortable with some imminent danger and forced you to compensate without thinking, and then you start thinking about what just happened. "Why did I suddenly step back from the ledge? Huh, must've been thinking about jumping off."
Another hypothesis I've read (which I can't find a good link to at the moment) is that it's some self-test mechanism. Your brain kind of sends a false "What if?" signal, and you should dismiss it because of the discomfort. This dismissal causes heightened awareness of the danger imminent and causes you to be more alert and thus be safer.
Again, though, these are pretty normal. That link I shared estimates that 50% of people have experienced the "call of the void". It's really only an issue if they're extraordinarily frequent (like... all the time), or if you genuinely feel tempted to act on them. Intrusive thoughts are not always indicative of suicidal ideation, but have also been linked to OCD and similar anxiety disorders (because they're a weird coping mechanism, when you think about it).
I've always had an odd pleasure at standing at the edge of cliffs. Something meditative about trying to overcome the feeling of unbalance. Think about it, you can be perfectly balanced standing on a cubic foot of rock. But if it's suspended hundreds of feet in the air, you would feel unbalanced (wind notwithstanding).
It turns out that this actually is dangerous. The feeling of imbalance is a "real" reaction your body has.
I seem to remember Sartre saying interesting things about this idea. Something about exercising your absolute freedom or something. As far as I know, it's perfectly normal.
I remember reading these are called parasitic(?) thoughts, uncontrollable and random thoughts, sometimes leading to more complex reasoning but ultimately almost on autopilot ; like the mind is just suggesting many different things at once and you just happen to notice one of those random thinking when it reaches the surface of your consciousness. I belive it also has to do with an anxious mind but I have nothing to back that up.
I think I remember reading somewhere that thinking about jumping when you are near a staircase, balcony, cliff, or something like that is pretty common, even if you don't have the least desire to commit suicide otherwise.