The lottery is much less efficient than most form of gambling than most because each lottery ticket has an expected loss of more than 50% after taxes whereas slot machines have an expected loss of only about 10% and the stock market actually has a real expected gain of about 7% per year in the long run if stocks are picked randomly. (Unfortunately, most people, including experts, do worse than random when they put effort into deliberately picking individual stocks). Although the lottery is inefficient it appeals to the minority of Americans who buys lottery tickets.
But why buy lotto tickets when there are much more efficient ways to gamble? Ben Orlin wrote a great explainer for all the theories why people buy lotto tickets, but only a few theories explain why anyone would prefer a gamble that is so much worse than most other gambling opportunities. I think the best explanation is The Dreamer. A lotto ticket is like a movie ticket for daydreams in which the buyer is the star of the show. Because the maximum potential lotto win is bigger than in any other gamble, it helps paint a more dramatic possible life story than any other form of gambling with smaller payouts.