DEV Community

loading...

Lottery Simulation in Elm

ryan senn
Software engineer and founder of Tradie Training. Tradie Training is an education company based in Brisbane, Queensland Australia. We specialise in OHS training such as the White Card course.
・2 min read

Hi all,

A while back, I came across a cool article published by the Los Angeles Times, where you start with $100 and simulate playing the Powerball (written in JS).

It inspired me to write an Australian Powerball version (the number of balls, barrel sizes etc are different) in Elm, which I'm hosting on my personal website. The app is pretty rough, it was to try out Elm 0.19.1 (upgrade from 0.19). I shared it on reddit on the Australian Finance sub and got overwhelmingly positive feedback.

With the whole lockdown thing happening now and to keep myself busy, I decided to created a website dedicated to lottery simulations. It now includes all popular lotteries such as the US Powerball, US Mega Millions, Euro Jackpot, Euro Millions as well as the most popular Australian Lotteries. I have also put in more effort on the UX level.

I think that Elm's strong static types really helped me during the development of this app. Not knowing much about lotteries before jumping in, there were many refactors along the way. I did not expect the European lotteries to have multiple "Powerballs" for example (called Euro numbers and Lucky stars). The application also has to support games such as OZ lotto, where there is a single barrel, and the last 2 numbers are complimentary numbers etc. Even with a lot of experience with dynamic languages such as Elixir, I think that static types and the friendly compiler messages kept me sane.

All the lotteries use the same code base, the behaviour is dictated by the config that gets injected.

The site is running on a simple Elixir/Phoenix backend with only a few tasks:

  • Rendering the pages where Elm mounts itself
  • GenServer to crawl the current Jackpots
  • GenServer to crawl recent draws and dividends

If you have a play around to test your luck, I would love to hear about your feedback!

Discussion (0)