title: Using random values obtained from the global random number generator in Haskell in arithmetic and logic operations
body: <p>How do you use <code>IO Double</code> values obtained from the global random number generator in Haskell in arithmetic and logic operations? Most tutorials on the internet focus on obtaining random numbers, but somehow I seem not to be able to do something useful with them.</p>
  
  <p>The following code contains some function <code>test</code> containing some of the operations I want to perform. </p>
  
  <pre><code>{-# LANGUAGE Strict #-}
  module RNG where
  import System.Random(setStdGen, mkStdGen, randomRIO)
  
  seed_rng :: Int -&gt; IO()
  seed_rng seed = (setStdGen (mkStdGen seed))
  
  uniform_float :: IO Double
  uniform_float = (randomRIO (0.0, 1.0))
  
  test :: Double -&gt; Double -&gt; IO Double
  test a b = let u = (uniform_float)
                in if ((&lt;) (return a) u) then ((+) (return b) u) else (return 2.0)
  </code></pre>
  
  <p>The test function does not compile since there is no instance for <code>Ord (IO Double)</code> and <code>Num (IO Double)</code>.</p>
  
  <p>Note that I can avoid the <code>IO Monad</code> by implementing a random number generator and tracking+passing the state myself. But I rather learn to work with <code>Monads</code> instead of always trying to run away from them.</p>