"Working through a pretty ugly project, I came across this C# beauty," Matt B writes, "at first, I was unsure of what it did. I was utterly perplexed until I took a second look at the function name. "

"It turns out, it produces a random string of letters. It was used to create a random ID for some URLs. Apparently, this developer was too proud for base 64 encoding, MD5, or some good old ASCII conversion."

protected String getRanString()
{
    String uncleanRandomString = System.Web.Security.Membership.GeneratePassword(10, 0);
    uncleanRandomString = uncleanRandomString.Replace("!", "a");
    uncleanRandomString = uncleanRandomString.Replace("@", "2");
    uncleanRandomString = uncleanRandomString.Replace("#", "c");
    uncleanRandomString = uncleanRandomString.Replace("$", "4");
    uncleanRandomString = uncleanRandomString.Replace("%", "3");
    uncleanRandomString = uncleanRandomString.Replace("^", "i");
    uncleanRandomString = uncleanRandomString.Replace("&", "a");
    uncleanRandomString = uncleanRandomString.Replace("*", "9");
    uncleanRandomString = uncleanRandomString.Replace("(", "g");
    uncleanRandomString = uncleanRandomString.Replace(")", "m");
    uncleanRandomString = uncleanRandomString.Replace("_", "d");
    uncleanRandomString = uncleanRandomString.Replace("-", "5");
    uncleanRandomString = uncleanRandomString.Replace("+", "p");
    uncleanRandomString = uncleanRandomString.Replace("=", "q");
    uncleanRandomString = uncleanRandomString.Replace("[", "w");
    uncleanRandomString = uncleanRandomString.Replace("{", "t");
    uncleanRandomString = uncleanRandomString.Replace("]", "r");
    uncleanRandomString = uncleanRandomString.Replace("}", "f");
    uncleanRandomString = uncleanRandomString.Replace(";", "8");
    uncleanRandomString = uncleanRandomString.Replace(":", "z");
    uncleanRandomString = uncleanRandomString.Replace("<", "x");
    uncleanRandomString = uncleanRandomString.Replace(">", "0");
    uncleanRandomString = uncleanRandomString.Replace("|", "v");
    uncleanRandomString = uncleanRandomString.Replace(".", "b");
    uncleanRandomString = uncleanRandomString.Replace("/", "y");
    uncleanRandomString = uncleanRandomString.Replace("?", "t");
    return uncleanRandomString;
}
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!