Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public string GeraSenhaAleatoria(int tamanhoSenha)
char[] possiveisCaracteres = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$&".ToArray();
// criar um IEnumerable<bool> com o total de itens definido tamanhoSenha
string senha = Enumerable.Repeat(true, tamanhoSenha)
// Seleciona, randomicamente, alguns caracteres e retorna um IEnumerable<char> com caracteres aleatórios
.Select(c => possiveisCaracteres[rnd.Next(possiveisCaracteres.Length)])
// Junta todos os caracteres em uma única string
.Aggregate(String.Empty, (current, next) => current.ToString() + next.ToString());
return senha;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.