Advertisement
campos20

Untitled

May 20th, 2020
1,524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. // Gera senha aleatoria
  6. // Autor Alexandre Campos
  7.  
  8. // Gera 1 numero aleatorio ate um limite
  9. int numero_aleatorio(int maximo)
  10. {
  11.     return random() % maximo;
  12. }
  13.  
  14. char gera_char_aleatorio()
  15. {
  16.    // Retorna aleatorio entre a e a+26 (sao 26 letras)
  17.     return 'a' + numero_aleatorio(26);
  18. }
  19.  
  20. int main()
  21. {
  22.     // Chamar 1 vez
  23.     srand(time(NULL));
  24.  
  25.     for (int i=0; i<100; i++)
  26.     {
  27.         char resultado = gera_char_aleatorio();
  28.         int codigo = resultado;
  29.         printf("Char: %c\n", resultado);
  30.     }
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement