title: How do I create a Vec from a range and shuffle it?
body: <p>I have the following code:</p>
  
  <pre><code>extern crate rand;
  
  use rand::{thread_rng, Rng};
  
  fn main() {
      let mut vec: Vec&lt;u32&gt; = (0..10).collect();
      let mut slice: &amp;[u32] = vec.as_mut_slice();
  
      thread_rng().shuffle(slice);
  }
  </code></pre>
  
  <p>and get the following error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0308]: mismatched types
   --&gt; src/main.rs:9:26
    |
  9 |     thread_rng().shuffle(slice);
    |                          ^^^^^ types differ in mutability
    |
    = note: expected type `&amp;mut [_]`
               found type `&amp;[u32]`
  </code></pre>
  
  <p>I think I understand that the content of vectors and slices is immutable and that causes the error here, but I'm unsure.</p>
  
  <p>The signature of <code>as_mut_slice</code> is <code>pub fn as_mut_slice&lt;'a&gt;(&amp;'a mut self) -&gt; &amp;'a mut [T]</code>, so the slice should be mutable, but it somehow isn't.</p>
  
  <p>I know that there must be an easy fix, but I tried my best and couldn't get it to work.</p>