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.

40,039 questions

52,004 answers

573 users

How to generate a random letter in C

1 Answer

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

char generate_random_letter(void) {
    char random_letter;
    int random_index = rand() % 52;
    
    if (random_index < 26) {
        random_letter = 'A' + random_index;
    } else {
        random_letter = 'a' + random_index - 26;
    }
    
    return random_letter;
}

int main() {
    srand(time(NULL));
    
    printf("%c\n", generate_random_letter());
    
    printf("%c\n", generate_random_letter());
    
    return 0;
}





 
/*
run:
   
O
q
 
*/


 



answered Mar 11, 2024 by avibootz
...