Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- // Gera senha aleatoria
- // Autor Alexandre Campos
- // Gera 1 numero aleatorio ate um limite
- int numero_aleatorio(int maximo)
- {
- return random() % maximo;
- }
- char gera_char_aleatorio()
- {
- // Retorna aleatorio entre a e a+26 (sao 26 letras), ou seja, de a ate z
- return 'a' + numero_aleatorio(26);
- }
- char * gera_senha(int tamanho){
- // Aloca o espaco
- char * resultado = malloc(tamanho * sizeof(char));
- // Preencher a senha com caracteres aleatorios
- for (int i=0; i<tamanho; i++){
- resultado[i] = gera_char_aleatorio();
- }
- return resultado;
- }
- int main()
- {
- // Chamar 1 vez
- srand(time(NULL));
- // Declaracao
- int tamanho_da_senha = 10;
- char * senha = gera_senha(tamanho_da_senha);
- // Exibe a senha
- printf("%s", senha);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement