How to pick a random character from a string in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
 
int main(void) {
    char str[] = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_-=+]}[{;:'/?.><,|`~";
 
    int size = strlen(str);
 
    srand((unsigned int)time(NULL));
 
    char ch = str[rand() % (size - 1)];
 
    printf("%c", ch);
 
    return 0;
}
 
 
 
/*
run:
   
j
   
*/


 



answered Feb 2, 2024 by avibootz

Related questions

1 answer 113 views
1 answer 172 views
1 answer 171 views
1 answer 139 views
1 answer 139 views
1 answer 140 views
140 views asked Nov 22, 2022 by avibootz
...