I've read this comparison in the past, and do not think it's all that valid.
Owning stocks is owning a piece, however tiny, of a business which one would hope is producing goods and services for society, and most folks who so invest are looking for a gradual, modest return, not a get-rich-quick objective.
When my state's lottery was created thru citizen referendum 40+ years back, I voted against it, out of conviction that it was a poor way to fund state services, mainly because it encouraged the get-rich-quick-without-working mindset, but also because it would prey on those least able to afford it.
Shortly after the start of the state lottery, I was twice given a ticket by friends.
Because of the thought behind the gift, I accepted and checked for the results, and would gladly have offered a share of the winnings (there were none) to my church.
Having said that, I also have participated in the drawings for the moose season and for any-deer permits, as I see these as the fairest way to allocate a limited resource, and because "winning" gives one merely the opportunity to hunt a particular type of animal.
When the state changed the one-only chance in the moose drawing to one-for-$5/three-for-$10/six-for-$20, I dropped out due to that conviction.
I've never criticized anyone for continuing in the moose drawing (which just returned to one-only) or in the state lottery, but intend never to participate in the latter.
Here in WA State most of the proceeds go to the school system (or so we are told). They call it a voluntary tax. so there are two reasons that one can use to justify the purchase of a ticket and hey you might win.
Actually if it were a voluntary tax wouldn't (or shouldn't) all the money go to the school system?
BTW, I lived in Maine for 15 years in Montville about 20 miles out of Belfast - close to Liberty and Freedom Maine.