This post will discuss how to select random letters in C++.

A common solution to generate a random number between 0 and RAND_MAX is using the rand() function, defined in the <cstdlib> header. We can use it to generate a random letter between some specific range, as shown below for ASCII lowercase alphabet range a-z:

Download  Run Code

 
Don’t forget to pass a seed to the function srand(), preferably the current time. To generate a random uppercase letter, do like:

Download  Run Code

 
We can easily extend the above solution to generate values in ranges a-z and A-Z:

Download  Run Code

 
Finally, you can generate a random letter from ASCII alphanumeric range or any other specific character range as follows:

Download  Run Code

That’s all about selecting random letters in C++.