Random alphanumeric password generator with GOTOs I was inspired after this thread on Stack Overflow to create a random 8 character alphanumeric password generator.

Sadly, it is closed, so I cannot provide an answer there. Anyway, here is the code. Let me know if there are any bugs/bias going on.

using System.Collections.Generic;
using System.Security.Cryptography;

public class AlphanumericGen
{
    public virtual string Generate(byte length)
    {
        ICollection&lt;char&gt; chars = new LinkedList&lt;char&gt;();
        var buffer = new byte[1];
        short counter = 0;
        using (var rng = new RNGCryptoServiceProvider())
        {
            while (counter &lt; length)
            {
                rng.GetBytes(buffer);
                var nextChar = (char)buffer[0];

                if (nextChar &gt;= '0' &amp;&amp; nextChar &lt;= '9')
                {
                    goto addChar;
                }

                if (nextChar &gt;= 'A' &amp;&amp; nextChar &lt;= 'Z')
                {
                    goto addChar;
                }

                if (nextChar &gt;= 'a' &amp;&amp; nextChar &lt;= 'z')
                {
                    goto addChar;
                }

                continue;

            addChar:
                chars.Add(nextChar);
                ++counter;
            }
        }

        return string.Concat(chars);
    }
}
As a general rule of thumb, any time you feel the need to use goto, take a couple of aspirin and lay down until the feeling passes.  They probably should have been deprecated decades ago.

In this particular case, using a string of allowed characters and randomly picking an index in that string would do away with your goto's.

I think too a StringBuilder would do a lot better for storing the characters than a LinkedList.