LOTTERIES are widely derided as a tax on stupidity. The odds are heavily stacked against the ticket buyers. The randomized systems that select the winning numbers eradicate any trace of skill from the competition. But none of that diminishes my enthusiasm for having a weekly flutter on an arbitrary set of digits chosen by an algorithm.

During this year’s Tokyo 2020 Olympics, British athlete after British athlete thanked the National Lottery in general and ticket buyers in particular for helping to provide the financial support that made their medal dreams come true. Team GB won 65 medals in Tokyo, including 22 golds, putting it fourth in the table after Japan. That matched the overall tally when the games were held in the UK in 2012 and was just two short of the record achieved at the 2016 competition in Rio. Britain punches above its demographic weight on the Olympic stage — and lottery funding plays a significant role in paying for coaches and allowing sportspeople to dedicate themselves to full-time training.

UK Sports, which is responsible for funding British athletes, teams, and events, was set up in 1996 after the UK won just 15 medals at the Atlanta Olympics, putting it in 36th place in the medals table. The agency had a budget of £150 million ($207 million) for the financial year ended in 2020, of which more than £80 million came from lottery ticket sales. Its annual income, topped up by central government funding, meant it was able to invest £345 million on preparing athletes for the delayed Tokyo event, up from the £275 million spent on the Rio games and £264 million for the London Olympics.

“What the funding does, it gives anyone with a bit of talent a chance to go and perform,” said Jason Kenny, a British cyclist who added two podium finishes in Tokyo to boost his lifetime Olympics winnings to seven golds and two silvers, making him the nation’s most successful Olympian ever. “It has moved us up the medal tables massively.”

The UK isn’t the only country with a lottery that grants cash for social goods. Ireland, Sweden, the Netherlands, Germany, Spain, and Denmark all have licensed lottery operators designed to benefit local organizations, according to the Association of Charity Lotteries in Europe. But with annual ticket sales worth more than £8 billion, the UK lottery is by far the biggest in the region.

Moreover, the scale of the operation means the tickets I buy pay for more than just sports and the Olympics — more than £30 million a week are disbursed to charitable causes. In Wales, for example, a project called River and Sea Sense teaches youngsters about the dangers of swimming in open water as well as skills such as resuscitation. In Somerset, 60 projects have been funded during the past four years to help preserve the wetlands and wildlife of the Avalon Marshes.

Of course, playing the lottery is not all about altruism. My weekly investment — and I do regard it as an investment — purchases a few hours of fantasy about a life of luxurious leisure, where I’m sailing a superyacht rather than driving a desk. And while the status of millionaire isn’t what it was, I’d still count myself lucky to figure as one of the six Britons per week who achieve that rank courtesy of their lottery winnings. So, by buying lottery tickets I’m simultaneously doing good and buying a cheap dream of riches — what’s so stupid about that?