title: Rust: Error[E0277]: the trait bound `{integer}: SampleRange<_>` is not satisfied
body: <p>I have a line of code that is in a for loop, and it's supposed to generate a random number from 0 to 2499. It is giving me problems.</p>
  <pre><code>let index = rand::thread_rng().gen_range(2499);
  </code></pre>
  <p>Full code for those who want to know:</p>
  <pre><code>fn generate_phrase () -&gt; String {
  let mut phrase = String::new();
  let mut file = File::open(&quot;words.txt&quot;).expect(&quot;Failed to open words.txt&quot;);
  let mut contents = String::new();
  file.read_to_string(&amp;mut contents).expect(&quot;Failed to read words.txt&quot;);
  let words: Vec&lt;&amp;str&gt; = contents.split(&quot;\n&quot;).collect();
  for _ in 0..8 {
      let index = rand::thread_rng().gen_range(2499);
      phrase.push_str(words[index]);
      phrase.push(' ');
  }
  println!(&quot;Your phrase is: {:?}&quot;, phrase);
  return phrase;
  }
  </code></pre>
  <p>Error message:</p>
  <pre><code>error[E0277]: the trait bound `{integer}: SampleRange&lt;_&gt;` is not satisfied
     --&gt; src/crypto/crypto.rs:115:45
      |
  115 |    let index = rand::thread_rng().gen_range(2499);
      |                                   --------- ^^^^ the trait `SampleRange&lt;_&gt;` is not implemented for `{integer}`
      |                                   |
      |                                   required by a bound introduced by this call
      |
  note: required by a bound in `gen_range`
     --&gt; C:\Users\Administrator\.cargo\registry\src\github.com-1ecc6299db9ec823\rand-0.8.5\src\rng.rs:132:12
      |
  132 |         R: SampleRange&lt;T&gt;
      |            ^^^^^^^^^^^^^^ required by this bound in `gen_range
  </code></pre>
  <p>I know the problem, which is that the trait is not the right kind but I don't know how to convert the integer into the necessary trait: <code>SampleRange&lt;T&gt;</code>. I've looked on StackOverFlow and couldn't find an appropriate answer anywhere.</p>