[C #] NetxtString,
Key code:
/// <Summary> /// generate a random string /// </summary> /// <param name = "Random"> random </param> // <param name = "size"> String Length </param> /// <param name = "lowerCase"> the string is a lowerCase </param> /// <returns> random string </ returns> public static string NetxtString (this Random random, int size, bool lowerCase) {StringBuilder _ builder = new StringBuilder (size); int _ startChar = lowerCase? 97: 65; // 65 = A/97 = a for (int I = 0; I <size; I ++) _ builder. append (char) (26 * random. nextDouble () + _ startChar); return _ builder. toString ();}
Test code:
static void Main(string[] args) { try { Random _random = new Random(); for (int i = 0; i < 10; i++) { Console.WriteLine(_random.NetxtString(4, false)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.ReadLine(); } }
Test results:
/// <Summary> /// 0 ~ 9 ~ Z string // </summary> public static string RandomString_09AZ = "0123456789 ABCDEFGHIJKMLNOPQRSTUVWXYZ "; /// <summary> /// generate a random string based on the specified string /// </summary> /// <param name = "Random"> random </param>/ // <param name = "randomString"> specify the string </param> /// <param name = "size"> String Length </param> /// <param name = "lowerCase"> the string is a lowerCase </param> // <returns> Random string </returns> public static string NetxtString (this random Random, stri Ng randomString, int size, bool lowerCase) {string _ nextString = string. Empty; if (random! = Null &&! String. isNullOrEmpty (randomString) {StringBuilder _ builder = new StringBuilder (size); int _ maxCount = randomString. length-1; for (int I = 0; I <size; I ++) {int _ number = random. next (0, _ maxCount); _ builder. append (randomString [_ number]);} _ nextString = _ builder. toString ();} return lowerCase? _ NextString. ToLower (): _ nextString. ToUpper ();}
Test code:
static void Main(string[] args) { try { Random _random = new Random(); string _ramdomString = RandomToolV2.RandomString_09AZ; for (int i = 0; i < 20; i++) { // Console.WriteLine(_random.NetxtString(4, false)); Console.WriteLine(_random.NetxtString(_ramdomString, 4, false)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.ReadLine(); } }
Code effect:
Hope this is helpful!
What is PC
Personal computer, personal computer =
What is the PC end?
The PC end is the interface for accessing the personal computer. Some mobile phones should prompt pc capacity storage when accessing the computer, which means to access the personal computer. A pc is a personal computer. Permissioncomputer (PC) generally refers to terminals, user terminals, and clients.