+ 1

Code to develop random letter string in C.

I want to develop a code which generates random letter string of required length. I don't have any idea how to start. Does anyone have an idea?

30th Apr 2018, 4:02 PM
srihitha reddy
srihitha reddy - avatar
2 Antworten
+ 1
You need to be aware that C uses arrays of Char for string representation. Generating random characters can easily done with rand(). Since you know how many letters you need you can simply create a new string with Char random[x]; To create a random letter you can use rand(). It creates a random number between 0 and RAND_MAX. To get a random ascii lowercase letter you can simply do this: random[i] = (rand() % 27) + 97; To print it as a letter you need to tell the printing method to interpret numbers as ascii symbols. For example: printf("%c", random[i]);
2nd May 2018, 7:49 AM
TransHedgehog
TransHedgehog - avatar
0
I’m afraid not in C. This could be done very easily in python, if you decide to change your mind on the language however.
30th Apr 2018, 4:31 PM
Jax
Jax - avatar