How to generate random uppercase and lowercase characters in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h> 
#include <time.h>

int main(void) {
    srand((unsigned int) time(NULL) + getpid());
    
    char *letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    int letterslen = strlen(letters);

    int len = 10, total = 5;
    while (total--) {
        int tmp = len;
        while (tmp--) {
            putchar(letters[rand() % letterslen]);
            srand(rand());
        }
        printf("\n");
        tmp = len;
    }
 
    return 0;
}
  
  
  
/*
run :
  
kAzMULyCMU
IQGdxPvIST
gWWrMYOLdp
uKaJfCrnEH
uZeOeBxqFR
  
*/

 



answered Feb 14, 2021 by avibootz

Related questions

...