I think, โyou have to live with it,โ is neither useful nor right. It depends on the abstractions you use. If your application, of course, is connected with a monad, then it makes sense to use a random number generator with a monad, which is as convenient as a Java random number generator.
In the case of a game using modern abstractions, your application is naturally related to functional reactive programming (FRP), where random number generation is not a problem at all and does not require you to skip generators explicitly. An example of using the netwire library:
movingPoint :: MonadIO m => (Double, Double) -> Wire ma (Double, Double) movingPoint x0 = proc _ -> do -- Randomly fades in and out of existence. visible <- wackelkontakt -< () require -< (visible, ()) -- 'rnd' is a random value between -1 and 1. rnd <- noise1 -< () -- dx is the velocity. let dx = (sin &&& cos) (rnd * pi) -- Integration of dx over time gives us the point position. -- x0 is the starting point. integral x0 -< dx
Is there any way to express this easier and shorter? Probably not. FRP also proves that Zhen is not wrong. It can only handle user input.
source share