title: Why is `thread_rng()` called on `rand` and not `Rng`, like how `stdin()` called on `io`?
body: <p>I am at <a href="https://doc.rust-lang.org/stable/book/ch02-00-guessing-game-tutorial.html#generating-a-random-number" rel="nofollow noreferrer">Generating a Random Number</a> in <em>The Rust Programming Language</em>, but I am having trouble understanding the use of the library we add with the keyword <code>use</code>:</p>
  <pre class="lang-rust prettyprint-override"><code>use std::io;
  use rand::Rng;
  
  fn main() {
      println!(&quot;Guess the number!&quot;);
  
      let secret_number = rand::thread_rng().gen_range(1, 101);
  
      println!(&quot;The secret number is: {}&quot;, secret_number);
  
      println!(&quot;Please input your guess.&quot;);
  
      let mut guess = String::new();
  
      io::stdin()
          .read_line(&amp;mut guess)
          .expect(&quot;Failed to read line&quot;);
  
      println!(&quot;You guessed: {}&quot;, guess);
  }
  </code></pre>
  <p>We are loading two libraries, one we use with the code:</p>
  <pre class="lang-rust prettyprint-override"><code>io::stdin()
      .read_line(&amp;mut guess)
      .expect(&quot;Failed to read line&quot;);
  </code></pre>
  <p>and the other one we use with the code:</p>
  <pre><code>rand::thread_rng().gen_range(1, 101);
  </code></pre>
  <p>Why is the function <code>stdin()</code> called with the keyword <code>io</code> when the <code>thread_rng()</code> function is called with the keyword <code>rand</code> and not the keyword <code>Rng</code>?</p>
  <p>The book says that we can call <code>stdin()</code> with <code>std::io::stdin</code> if we didn't load the library, but I can't use <code>thread_rng()</code> from <code>rand::Rng</code> since the function is in <code>rand</code>.</p>
  <p>The book says that <code>Rng</code> is a trait to define methods, but I do not understand what it does and the difference between the <code>io</code> of <code>std::io</code> and the <code>Rng</code> of <code>rand::Rng</code>. Is <code>io</code> also a trait?</p>