title: How to generate a random number within a certain range using GMP
body: <p>I have tried to do this as follows:</p>
  
  <pre><code>int main(){
    mpz_t v;
    mpf_class u,w,x[3][200];     
  
    for(i=0;i&lt;n;i++){
     for(j=0;j&lt;3;j++){
       mpz_random(v,1000000);
       mpf_div_ui(w.get_mpf_t(),v,1000000);
       mpf_div(u.get_mpf_t(),1,2);
       mpf_sub(w.get_mpf_t(),w.get_mpf_t(),u);
       mpf_mul(x[i][j].get_mpf_t(),w.get_mpf_t(),2);
     }
    }
  }
  </code></pre>
  
  <p>But the use of integers and floats together doesn't work. Basically tried assigning random integer, dividing by the max the integer could be giving a number (not necessarily integer) between 0 and 1. Minus a half and multiply by 2 gives a random number between -1 and 1 which is what I want, but like I said this causes issues due to types.</p>