The broader version of this question is a common one and for the most part has been answered with the explanation that if one invests passively in the market (index funds) or in a company that you are familiar with, it isn't really gambling. Yet, the question is more complicated than that and I think very relevant in this sideways market.
To answer this question, let's first look at the word gambling. The two most common definitions have to do with "betting on an uncertain outcome" or "playing a game of chance for stakes." In addition, alternative definitions talk about "taking risks" or "engaging in reckless behavior." Let's settle on a definition of "risking something of value on an uncertain outcome for potential gain."
With this definition most types of market investing would be classified as gambling. Certainly, the money you invest would fall under the category of "something of value" and the appreciation of a stock is far from a certain outcome. So investing in the market is gambling.
But is that really bad?
Let's take a step back and ask another common question from my book tour: is card counting gambling? Going back to our aforementioned definition of gambling, certainly we risked "something of value" (up to $50,000/hand) and each individual hand of blackjack we played was far from a certain outcome so, yes, what we did could be considered gambling.
Yet here in lies the difference. Card counting is a pretty simple concept. You track cards that you have seen so that you can predict cards that you are going to see. By doing such you can actually calculate your odds of winning and can bet more when your odds are better and bet less when your odds are worse. This strategy can be proven sound mathematically and with proper money management and time horizon you can give yourself a fairly high probability (greater than 95% and with more conservative strategies greater than 99%) of winning in the long run (sometimes it took us close to a year in the casinos).
So in a nutshell we used money management and time horizon to reduce the uncertainty of our outcome and therefore reduce the gamble of our gamble.
This analogy works well in the market where unless you are Jim Simons, the longer your time horizon the more certain your outcome. Of course, if you don't allocate your resources properly based on your overall amount of cash, you may never be able to see the end of that time horizon. Proper money management helps drive down the uncertainty of your outcome and helps reduce the gamble of your gamble.
So what does this mean practically?
First of all, investing in the market is gambling and we all need to be comfortable with that. But in order to reduce the gamble we need to reduce the uncertainty of the outcome.
There are a few ways to do that: 1) Invest in instruments (index funds) that have predictable movement over time. 2) Have a time horizon (longer than a year) that allows that predictable movement to occur. 3) Utilize a money management (don't put all your eggs in one basket) strategy that allows you to remain in the game for the duration of your long time horizon.
Our success at the tables was not based on one hand of blackjack; rather, it was based on the knowledge that we would play hundreds of thousands of hands of blackjack in order to ensure that we weren't gambling.