title: does fisher yates shuffle based on index?
body: <p>i am currently doing leetcode to prepare for job interviews and i came across a shuffle challenge.
  I looked shuffles up and came across fisher yates shuffle method and i got curious to learn the basics.</p>
  <p>so my question is, how does this work?</p>
  <p>currently i figured that the random value takes the current index and adds a random value from 0 to 1 multiplied with the length of the array minus the current index.</p>
  <p>Here i am curious about if the random generates a value between 0 and length and places the shuffled value at that index, or if it generates a value there? i am a bit confused as i want to learn it and memorize it for the future</p>
  <p>this is the code:</p>
  <pre><code>static void Shuffle&lt;T&gt;(T[] array)
          {
              int n = array.Length;
              for (int i = 0; i &lt; n; i++)
              {
                  //_random.NextDouble() float &gt;= 0 and less than 1 float &gt;= 0 &lt; 1
                  // n = 4
                  int random = i + (int)(_random.NextDouble() * (n - i)); // int random = 0 + randNext * (4-0) = [0,4]
                                                                          // int random = 1 + randNext * (4-1) = [1,3]
                                                                          //int random =  2 + randNext * (4-2) = [2,2]
                                                                          //random =      3 + randNext * (4-3) = [
                  //Console.Write(&quot;rand is: &quot; + random + &quot; i: &quot; + i + &quot; next: &quot; + (int)(_random.NextDouble()*(n-i)));
                  T t = array[random];
                  array[random] = array[i]; // array[0,4] = array[0] = array[2] = 1
                  array[i] = t;
                  Console.WriteLine(array[i]);
              }
          }
  </code></pre>
  <p>basically im curious if anyone can tell me if my understand is correct or im misunderstanding the algorithm :D
  thx a lot</p>