title: How to generate a random integer in a range
body: <p>a program I'm writing requires me to simulate the mutation of genes. If a certain instance (J) of the gene is selected for mutation, it must randomly become one of a predefined subset of alternative genes. These discrete genes are marked by the integers in the range 0 to K-1, where K equals the total number of alleles.</p>
  
  <p>So basically, I need help writing the code to randomly select an integer in the range 0 to K-1 that does not equal J. Any help is greatly appreciated!</p>
  
  <p>ANOTHER EDIT: Thanks for all the help so far, I've come up with the following, which ignores the requirement that i cannot equal J. However, a further problem I've encountered is that the process must be repeated multiple times, and due to the same seed being used each time the value of i is always the same. How should I go about ensuring the seed value doesn't remain the same throughout every generation? Again, any help is greatly appreciated!</p>
  
  <pre><code>program randtest
  
  implicit none
  
    real*4        :: u(5)
    integer       :: i(5)
    integer       :: k = 4
    integer, dimension (1) :: seed = (/2817/)
  
    call random_seed(put=seed) 
  
    call random_number(u)
  
  i = floor((k+1)*u) 
  
   print *, i
  
   end program randtest
  </code></pre>