Created
December 15, 2015 20:19
-
-
Save leikind/7344504ec639fc96e83b to your computer and use it in GitHub Desktop.
A signal of random numbers every second where the first seed is a timestamp
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
| module SignalOfRandomNum where | |
| import Graphics.Element as GE | |
| import Time | |
| import Random | |
| import Maybe exposing (..) | |
| randomIntSignal : Int -> Int -> Signal Time.Time -> Signal Int | |
| randomIntSignal lo hi inputSignal = | |
| let | |
| intGen = Random.int lo hi | |
| nextRandom seed = | |
| seed | |
| |> Random.generate intGen | |
| |> Just | |
| update time accu = | |
| case accu of | |
| Just (_, seed) -> | |
| seed | |
| |> nextRandom | |
| Nothing -> | |
| round time | |
| |> Random.initialSeed | |
| |> nextRandom | |
| in | |
| inputSignal | |
| |> Signal.foldp update Nothing | |
| |> Signal.map (\maybe-> | |
| case maybe of | |
| Just (n,_) -> n | |
| Nothing -> -1 ) | |
| signalOfRandomIntEverySecond : Signal Int | |
| signalOfRandomIntEverySecond = | |
| Time.every Time.second |> randomIntSignal 1 100 | |
| main : Signal GE.Element | |
| main = | |
| Signal.map GE.show signalOfRandomIntEverySecond | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment