Generate a random letter in set range?

Hi guys.
I am making a bejewelled like game in windows console where if I get three of the same characters they will be destroyed and new characters will be added.
I have no idea how to generate a random letter either R, Y or B. I know that there is a rand() function but I am not sure if I can use it for characters or set a specific range to it.

I am really sorry if any of this is unclear or funny but I a complete newbie trying to get hang of it.
Well yes you can. If we're talking R,Y,B. Create a character array and define them.

char letters[3] = {'R', 'B', 'Y'};

Then use rand() to give you a number between 0-2.

Say you store the random number in a variable called int random.

You can juts do letters[random], which will give you R,B,Y depending on if the number is 0,1 or 2.

Last edited on
I am really great full TarikNeaj. It has really opened my eyes. Thank you so much
You're welcome buddy. It looks like you're new to this forum so I would advise you to read this for future posts - http://www.cplusplus.com/forum/beginner/1/

And to also use code tags if you ever need to post your code - http://www.cplusplus.com/articles/jEywvCM9/
Will do. I feel stupid, It even says Read before you post. Thanks again for help.
If that's a reason to be stupid, then 99.95% of people who post here are stupid.
Topic archived. No new replies allowed.