title: C# - Function to randomise case of four strings always returns each string in the same case
body: <p>I'm trying to build a basic random password generator in a Windows form. I have a list of words (all lower case), four of which get picked at random. Each word gets passed to a function to randomly change the case (capitalise the first character, capitalise the entire word, or just return the string in lower case) and then added to another list like so:  </p>
  
  <pre><code>var dictionary = new List&lt;String&gt; { "aaron", "abandoned", "aberdeen" etc... };
  int index;
  index = random.Next(dictionary.Count);
  string one = dictionary[index];
  one = randomCase(one);
  pwarray.Add(one);
  </code></pre>
  
  <p>This code is then duplicated for strings <code>two</code>, <code>three</code> and <code>four</code>. My function to randomise the case while not fancy is as so:</p>
  
  <pre><code>        private string randomCase (string word)
          {
              string changed;
              Random r = new Random();
              int n = r.Next(1, 29);
  
              // Output number to check it's not the same each time
              MessageBox.Show(n.ToString());
              if (n &gt;= 1 || n &lt;= 9)
              {
                  // First letter capatalised
                  changed = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(word.ToLower());
                  return changed;
              }
              else if (n &gt;= 10 || n &lt;= 19)
              {
                  // Word capitalised 
                  changed = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(word.ToUpper());
                  return changed;
              }
              else if (n &gt;= 20 || n &lt;= 29)
              {
                  // Word left as lower case
                  return word;
              }
  
              return null;
          }
  </code></pre>
  
  <p>I've added output message boxes to show what random number <code>n</code> is to aid with troubleshooting. When I run the app, I get different numbers from my <code>randomCase</code> function for <code>n</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/BtO3n.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BtO3n.png" alt="enter image description here"></a><a href="https://i.stack.imgur.com/eGBv6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eGBv6.png" alt="enter image description here"></a><a href="https://i.stack.imgur.com/a2njz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/a2njz.png" alt="enter image description here"></a><a href="https://i.stack.imgur.com/Ln8cy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ln8cy.png" alt="enter image description here"></a></p>
  
  <p>4 - First character capitalised</p>
  
  <p>17 - Word capitalised</p>
  
  <p>20 - Word left as lower case</p>
  
  <p>24 - word left as lower case</p>
  
  <p>However all four words have had the first letter capitalised: </p>
  
  <p><a href="https://i.stack.imgur.com/5INz9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5INz9.png" alt="enter image description here"></a>: </p>
  
  <p>I've generated many passwords and they always seem to come out in the same way - first letter capitalised only. Can anyone offer any suggestions?   </p>