using random to generate strings..

Now ,Random()[or rand()] is ,in my knowledge generally and only used to get random integers..

Suppose, I want to generate a random 3-character string that may contain
a-z
OR
A-Z

How to do this ?
Besides using random , is there any other way to do this ?
If it doesn't, get a random number between 'a' and 'z' or 'A' and 'Z'.
1
2
3
4
5
6
7
8
if(rand() % 2) // Generate a value. Depending on it...
{
    char ThisChar = (rand()%('Z'-'A')) + 'A'; // Generate a uppercase one
}
else // or...
{
    char ThisChar = (rand()%('z'-'a')) + 'a'; // Generate a lowercase one
}
1
2
3
4
5
6
7
8
string rand3LetterStr()
{
  char temp[4];
  for (int i = 0; i < 3; ++i)
    temp[i] = 65 + rand() % 26 + 32 * (rand() % 2);
  temp[3] = '\0';
  return temp;
}
Topic archived. No new replies allowed.