Created
August 19, 2015 06:23
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.