Are you serious?
Up until the dot.bomb. era, investing in the stock market was not supposed to be gambling. One did their homework, and studied the companies and the markets, etc., and did NOT restrict this study to reading press releases or pump-and-dump postings, etc., or blindly allow their broker to furnish "Hot tips from the oatbag" and churn their accounts every week.
However, now, I agree, there is not much difference..But that is not the way it was supposed to be.
The stock market, on average over the length of its existance, has returned a net gain of somewhere around 6-8%. It produces a gain due to growth. You aren't betting on numerical odds, you're investing in the ideas of the leaders of the company you choose to produce a money-making idea. Yes, there are up and down periods, but over the long haul (and that can be very long), a diverse portfolio will gain. Its almost guaranteed. Almost...
The lottery is purely a game of chance, but the odds don't match the payout. First, the initial odds of winning are purely numerically based. Second, those odds aren't close to matching the actual payout - that is, if a given lottery has a 1/10,000,000 chance of drawing the winning numbers, you can bet (no pun intended) that the average payout is a lot less than 10,000,000 dollars. This is known as the 'house edge'. Since the state is the "house", it gets the edge. I don't have exact figures, but the total lottery payout vs. money taken in is something like 50%, more or less.