I'm an amateur at programming and have created the following method with which I pass a lowercase string with the idea it is then returned either in it's original lowercase
format, Capitalised
or UPPERCASE
. I'm not sure this is the best way or is truly "random" but does work up to a point but would like pointers on any improvements or different ways to achieve this.
//==============================================================================
// Randomise string case
//==============================================================================
private string randomCase (string word)
{
string changed;
Random r = new Random(Guid.NewGuid().GetHashCode());
int n = r.Next(1, 29);
if (n >= 1 && n <= 9)
{
// First letter capatalised
changed = char.ToUpper(word[0]) + word.Substring(1);
return changed;
}
else if (n >= 10 && n <= 19)
{
// Word capatalised
changed = word.ToUpper();
return changed;
}
else if (n >= 20 && n <= 29)
{
// Left as lower case
return word;
}
return null;
}