/ Published in: C#

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public class RandomStringGenerator { private Random r; const string UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const string LOWERCASE = "abcdefghijklmnopqrstuvwxyz"; const string NUMBERS = "0123456789"; const string SYMBOLS = @"~`!@#$%^&*()-_=+<>?:,./\[]{}|'"; public RandomStringGenerator() { } public RandomStringGenerator(int seed) { } public virtual string NextString(int length) { return NextString(length, true, true, true, true); } public virtual string NextString(int length, bool lowerCase, bool upperCase, bool numbers, bool symbols) { string charPool = string.Empty; //Build character pool if (lowerCase) charPool += LOWERCASE; if (upperCase) charPool += UPPERCASE; if (numbers) charPool += NUMBERS; if (symbols) charPool += SYMBOLS; //Build the output character array for (int i = 0; i < charArray.Length; i++) { //Pick a random integer in the character pool int index = r.Next(0, charPool.Length); //Set it to the output character array charArray[i] = charPool[index]; } } }
URL: http://www.vcskicks.com/random-string-generator.php
Comments
