Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,971 questions

51,913 answers

573 users

How to generate random uppercase characters in C

2 Answers

0 votes
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h> 
 
int main(void) {
    srand((unsigned int) time(NULL) + getpid());
 
    int len = 10, total = 5;
    while (total--) {
        int tmp = len;
        while (tmp--) {
            putchar('A' + (rand() % 26));
            srand(rand());
        }
        printf("\n");
        tmp = len;
    }
 
    return 0;
}
  
  
  
/*
run :
  
DZHDMKOYSL
OZTHGNWDHI
LHNGPGFLQW
TNKEQOKFMO
QSYKKCHCEV
  
*/

 



answered Feb 14, 2021 by avibootz
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 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    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 :
  
KDOEWPSKCL
VFUNGTLSIT
VNCCQMGIDV
TNYWBZDHTS
EXCOLPEVME
  
*/

 



answered Feb 14, 2021 by avibootz

Related questions

1 answer 163 views
1 answer 164 views
1 answer 83 views
1 answer 114 views
1 answer 135 views
1 answer 143 views
...