Random walk: simulating dice-playing with Elm
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 Elm — and this update