Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

23 linhas
758 B

  1. using System;
  2. using System.Linq;
  3. namespace Infrastructure
  4. {
  5. public static class RandomGenerator
  6. {
  7. private static readonly string numbers = "0123456789";
  8. private static readonly string lowercases = "abcdefghijklmnopqrstuvwxyz";
  9. private static readonly string uppercases = lowercases.ToUpper();
  10. public static string GetRandomString(int length, bool number = true, bool lowercase = false, bool uppercase = false)
  11. {
  12. var pool = $"{(number ? numbers : "")}{(lowercase ? lowercases : "")}{(uppercase ? uppercases : "")}";
  13. var generator = new Random();
  14. return new string(Enumerable.Repeat(pool, length).Select(s => s[generator.Next(s.Length)]).ToArray());
  15. }
  16. }
  17. }