DEV Community

ryan senn
ryan senn

Posted on

2

Lottery Simulation in Elm

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!

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (1)

Collapse
 
lunchtime444 profile image
lunchtime

Your project sounds fascinating! A lottery simulation website is a fun way to explore game mechanics, and it’s great you’ve included diverse lotteries. I’ll check it out during my lunchtime break to test my 'luck' I am looking forward to seeing the UX improvements and Elm in action!

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay