title: random characters in c
body: <p>I wrote a program that attempts to "guess" a word by randomly choosing characters.  However, my program is printing characters that are not in my character list.  What is going on here?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  #include &lt;string.h&gt;
  
  int main(){
  
      int index, i;
      time_t t;
      char characters[] = "bdefgir";
      char word[] = "friedberg";
      srand((unsigned)time(&amp;t));
      char result[9] = {0};
  
      while(strcmp(result, word) != 0){
  
          for (i = 0; i &lt; 9; i++) {
              index = rand() % 8;
              result[i] = characters[index];
          }
          printf("Result:\t%s\n", result);
  
      }
  
      return 0;
  
  }
  </code></pre>