title: Random Integer in Haskell
body: <p>I am in the process of learning Haskell and to learn I want to generate a random Int type.  I am confused because the following code works.  Basically, I want an Int not an IO Int.</p>
  
  <p>In ghci this works:</p>
  
  <pre><code>Prelude&gt; import System.Random
  Prelude System.Random&gt; foo &lt;- getStdRandom (randomR (1,1000000))
  Prelude System.Random&gt; fromIntegral foo :: Int
  734077
  Prelude System.Random&gt; let bar = fromIntegral foo :: Int
  Prelude System.Random&gt; bar
  734077
  Prelude System.Random&gt; :t bar
  bar :: Int
  </code></pre>
  
  <p>So when I try to wrap this up with do it fails and I don't understand why.</p>
  
  <pre><code>randomInt = do
      tmp &lt;- getStdRandom (randomR (1,1000000))
      fromIntegral tmp :: Int
  </code></pre>
  
  <p>The compiler produces the following:</p>
  
  <pre><code>Couldn't match expected type `IO b0' with actual type `Int'
  In a stmt of a 'do' block: fromIntegral tmp :: Int
  In the expression:
    do { tmp &lt;- getStdRandom (randomR (1, 1000000));
           fromIntegral tmp :: Int }
  In an equation for `randomInt':
      randomInt
        = do { tmp &lt;- getStdRandom (randomR (1, 1000000));
                 fromIntegral tmp :: Int }
  Failed, modules loaded: none.
  </code></pre>
  
  <p>I am new to Haskell, so if there is a better way to generate a random Int without do that would be preferred. </p>
  
  <p>So my question is, why does my function not work and is there a better way to get a random Int.</p>