Random walk: simulating dice-playing with Elm

Image for post
Image for post

The Elm language is much more than a (fantastic) tool for creating front-ends for web apps. The little example pictured above shows how it can be used to simulate and visualize a simple dice-playing game. The player begins with $4 and repeatedly rolls a die. If it comes up even, he wins a dollar. If it comes up odd, he loses a dollar. The code is here, on GitHub, along with instructions for installing and running it. The main file, src/randomWalk.elm , imports the module from Graph , housed also in src/ . The code has lots of comments, and you can use Graph.render to draw your own graphs.

See also: Making drawings with Elmand this update

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store