C++ program to generate random alphabets and store them into a character array
Random is one of the most cumbersome concepts to understand in C++. Multiple functions with same name are sort of confusing even for experienced programmers. However, applying them correctly can be fun. Here is a simple program that will print the alphabets in a random manner.
Consider the program:
Output
In this program first we take two character arrays, one to store all the alphabets and other to print random characters into it. To keep it simple we have taken the length as 20.
Now we initialize the seed to current system time so that every time a new random seed is generated.
Next, in the while loop, we loop through the length of the random string (20 here) and store random generated alphabets. We take a temp variable to generate a number between 0-26. Then we provide this number to alphabets array and a random string is generated.
After that we print the final random generated string.
need an explanation for this answer? contact us directly to get an explanation for this answer