Skip to content

Instantly share code, notes, and snippets.

@basti1302
Created August 19, 2015 06:23
Show Gist options
  • Save basti1302/b37b7b7aa38593127e25 to your computer and use it in GitHub Desktop.
Save basti1302/b37b7b7aa38593127e25 to your computer and use it in GitHub Desktop.
Creating a steady timed signal from random and feeding it into HTML output
import Html exposing (..)
import Random
import Random exposing (Seed)
import Signal exposing (Signal, (<~), (~))
import Time exposing (every, second)
randomFloat : Seed -> Float
randomFloat seed = seed |> (Random.generate <| Random.float 0 1) |> fst
randomBool : Seed -> Bool
randomBool seed = randomFloat seed |> (\f -> if f > 0.5 then True else False)
timedSeedSignal : Signal Seed
timedSeedSignal = Random.initialSeed << round <~ every second
randomBoolSignal : Signal Bool
randomBoolSignal = randomBool <~ timedSeedSignal
main : Signal Html
main = (\b -> p [] [text <| toString b]) <~ randomBoolSignal
@basti1302
Copy link
Author

I had quite a hard time trying to figure out how to create a random signal in elm and displaying it, so when I finally had something working, I thought I might just drop it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment