char cch = 'a' + rand()%26;
#include <iostream>
int main() {
srand(time(0));
std::cout <<"random uppercase = " << char('A' + rand() % 26) << std::endl;
// or
std::cout <<"random uppercase = " << char('a' + rand() % 26) << std::endl;
}
char c;
int r;
srand (time(NULL)); // initialize the random number generator
for (i=0; i<num; i++)
{ r = rand() % 26; // generate a random number
c = 'a' + r; // Convert to a character from a-z
cout << c;
}
Code Example |
---|
Cpp :: c++ string remove last character |
Cpp :: sort function from bigest to smallest c++ |
Cpp :: minimum spanning trees c++ |
Cpp :: c++ rand |
Cpp :: c++ memory leak |
Cpp :: qt popup window |
Cpp :: taking a vector in c++ containing element |
Cpp :: c++ infinite for loop |
Cpp :: Appending a vector to a vector in C++ |
Cpp :: how to clear console c++ |
Cpp :: cpp macro |
Cpp :: c++ program to find prime number using function |
Cpp :: c++ check if char is number |
Cpp :: reverse c++ |
Cpp :: string vector c++ |
Cpp :: c++ pointer null vs nullptr |
Cpp :: c++ vector loop delete |
Cpp :: c++ simple car game |
Cpp :: find max value in array c++ |
Cpp :: less than operator overloading in c++ |
Cpp :: Story of c++ |
Cpp :: how to add an element to std::map |
Cpp :: sort a 2d vector c++ stl |
Cpp :: functors in c++ |
Cpp :: cin.getline |
Cpp :: fast way to check if a number is prime C++ |
Cpp :: pascal triangle using c++ |
Cpp :: c++ add to array |
Cpp :: cpp absolute value |
Cpp :: classes and objects in c++ |