title: I'm trying to generate 7 random scrabble characters, but I'm getting more than 7 values stored
body: <pre><code>//This program is a basic scrabble game with some error checking.
  #include &lt;stdbool.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  
  #define num_letters 7
  #define tiles_max 100
  //value 1 and 2 are the same, they were passed from a generate letter set if statement to determine the max
  //value of things to add up
  int sum_array (int value1, int letter_set[], int value2, int tile_set[]){
    int counter2, sum_of_array;
    sum_of_array = 0;
    for(counter2 = 0; counter2 &lt; value1; counter2++){
      sum_of_array += tile_set[counter2] - letter_set[counter2];
    }
    return sum_of_array;
  }
  
  void generate_letter_set (int letter_set[], int size_letter_set, int lettersbgood){
    const int tile_set[] = {9, 2, 2, 4, 12, 2, 3, 2, 9, 1, 1, 4, 2, 6, 8, 2, 1, 6, 4, 6, 4, 2, 2, 1, 2, 1, 2};
    int counter1, counter3, chargen;
    srand((unsigned) time(NULL));
    for(counter1 = 0; counter1 &lt; lettersbgood; counter1++){
      chargen = rand() % (tiles_max - counter1);
      for(counter3 = 0; counter3 &lt; 27; counter3++){
        if(chargen &gt;= sum_array(counter3, letter_set, counter3, tile_set) &amp;&amp; chargen &lt; (sum_array(counter3, letter_set, counter3, tile_set)+(tile_set[counter3]-letter_set[counter3]))){
      letter_set[counter3] += 1;
        }
      }
    }
  }
  
  int main()
  {
    int size_letter_set = 27, counter4;
    int letter_set[27] = {0};
    printf("This program plays a game of scrabble.\n");
    generate_letter_set(letter_set, size_letter_set, num_letters);
    printf("Your letters are: \n");
    for(counter4 = 0; counter4 &lt; size_letter_set; counter4++){
      printf("%d ", letter_set[counter4]);
    }
    return 0;
  }
  </code></pre>
  
  <p>I am expecting it to print out at most 7 nonzero characters adding up to 7 and at least 1 nonzero character adding up to 7 and the rest as zeroes.</p>
  
  <p>What I get instead is various numbers of nonzero characters totaling more than 7.</p>
  
  <p>Sample output: 0 0 0 1 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 0 0 1 1 1 0 0
  Sometimes there are 2's or 3's as well. This program uses the c99 standard.</p>
  
  <p>I'd like to know why it's producing too many inputs (I think it's going through the loop too many times). Thanks in advance for your assistance.</p>