random character generate

hello everyone
char c,g;
for(i =0; i <1; i++)
{
c=(rand()%1) + 'A';//i know if i set the rand() function like this
g=(rand()%1) + 'a';//when i cout ill only get 'Aa'
}
cout << c << g
i want to generate a capital A and a lower case a
my output should be AA,Aa,aa it can not be aA i dont know how to restrict it form doing that
i honestly thought about doing a character Array
Last edited on
a clunky way:

char tbl[] = "Aa";
c = tbl[rand()%2];
g = tbl[rand()%2];
if(c == 'a')
g = 'a';

a cleaner way:
would be to make an array of strings, "AA","Aa","aa" and pick one of the 3 with rand()%3

Last edited on
so would it be something like this
string blah[3] ={"Aa" "AA" "aa"};

how would i initialize it with rand()%3// i understand it going to pick bettween 0-3

would i need a for loop :

for(int i=0; i< 3 i++)
{
blah[i]=rand()%3
}
??
it is initialized already.
it contains your 3 possible outcomes.

they need commas, though.

its

string blah[3] = {"AA","Aa","aa"};

these are not code, these are things you should know:
blah[0] is = "AA"
blah[1][1] is = 'a'
blah[1][0] is = 'A'

Topic archived. No new replies allowed.