Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Build a random string (See related posts)

/// <summary>
/// Build a random string (for id, login, password...)
/// </summary>
public static string randomString() {
	int length = new Random().Next(6, 10);
	return randomString(length);
}

/// <summary>
/// Build a random string (for id, login, password...)
/// </summary>
public static string randomString(int length) {
	string tempString = Guid.NewGuid().ToString().ToLower();
	tempString = tempString.Replace("-", "");
	while (tempString.Length < length) {
		tempString += tempString;
	}
	tempString = tempString.Substring(0, length);
	return tempString;
}

You need to create an account or log in to post comments to this site.


Click here to browse all 4858 code snippets

Related Posts