You are correct in supposing that an opposite of lower doesn't make sense.
In this particular case, the builtin Random library is builtin because it's a wrapper around a native JavaScript call. This is the reason for the Signal
return type, to keep the code pure. And even then, it's not completely well-behaved.
To get the kind of random range you want, you'll need a different random number generator. There is a community library that was published only a few days ago, that'll probably answer your needs. You can check it out of GitHub yourself, or use the elm-get
tool.
Your code would become something like (untested!):
import Window
import Generator
import Generator.Standard as GStd
randomSeed = 12346789
writeRandom : Signal Int -> Signal Element
writeRandom x =
let update high (_, gen) = Generator.int32Range (0,high) gen
start = (0, GStd.generator randomSeed)
input = sampleOn (every second) x
result = fst <~ foldp update start input
in lift asText result
upperLimit = Window.width
main = writeRandom upperLimit
In writeRandom
, you use foldp
to keep the latest random-number generator. In update
you use this to get a new random number and a new generator for the next time. The input of x
is updated every second by using sampleOn (every second)
. The fst <~
part is to remove the random number generator, since you only want the random number.