title: SIMPLE random number generation
body: <p>I'm writing this after a good while of frustrating research, and I'm hoping someone here can enlighten me about the topic.</p>
  
  <p>I want to generate a simple random number in a haskell function, but alas, this seems impossible to do without all sorts of non-trivial elements, such as Monads, asignation in "do", creating generators, etc.</p>
  
  <p>Ideally I was looking for an equivalent of C's "rand()". But after much searching I'm pretty convinced there is no such thing, because of how the language is designed. (If there is, please someone enlighten me). As that doesn't seem feasible, I'd like to find a way to get a random number for my particular problem, and a general explanation on how it works to get a random number.</p>
  
  <pre><code>prefixGenerator :: (Ord a, Arbitrary a) =&gt; Gen ([a],[a])
  prefixGenerator = frequency [ 
      (1, return ([],[])),
      (2, do {
              xs1 &lt;- orderedListEj13 ;
              xs2 &lt;- orderedListEj13 ;
              return (xs1,xs2)
         }),
      (2, do {                
              xs2 &lt;- orderedListEj13 ;
              return ((take RANDOMNUMBERHERE xs2),xs2)
         })
      ]
  </code></pre>
  
  <p>I'm trying to get to grips with QuickCheck but my inability to use random numbers is making it hard. I've tried something like <a href="http://zvon.org/other/haskell/Outputrandom/randomR_f.html" rel="nofollow">this</a> (by putting an drawInt 0 (length xs2) instead of RANDOMNUMBERHERE)but I get stuck with the fact that take requires an Int and that method leaves me with a IO Int, which seems impossible to transform to an Int according to <a href="http://www.haskell.org/pipermail/haskell-cafe/2009-June/062673.html" rel="nofollow">this</a>.</p>