title: How to generate a unique list of integers within a range in Scheme. (DrRacket)
body: <p>I have been having some trouble trying to define a function which generates a list of length x of random integers within the range [0, y). Here is the code to generate a list of random integers: </p>
  
  <pre><code>(define (random-list range list-length)
    (cond
      [(zero? length) empty]
      [else (cons (random range) (random-list range (sub1 list-length)))]))
  </code></pre>
  
  <p>The trouble is that if i try to turn this code into one that generates a list of unique random integers from 0 to (range - 1)  of length (list-length) using recursion. I cannot seem to find a way to check if the random number generated is already in the list that is being created. This code runs forever:</p>
  
  <pre><code>(define (random-list range list-length)
    (cond
      [(zero? list-length) empty]
      [else
       (cond
         [(member? (random range) (random-list range list-length))
          (random-list range list-length)]
         [else
          (random-list range (sub1 list-length))])]))
  </code></pre>
  
  <p>Any ideas? (I'm using DrRacket, Beginning Student)</p>