How to generate random uppercase, lowercase and numbers 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 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
    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 :
  
wvmj3D7A05
emgGmVcG9P
dRRt17O9Ja
VgE8f9bO4j
5ucKoKNl8J
  
*/

 



answered Feb 14, 2021 by avibootz

Related questions

...