random number generation

I am still working on my word search generator so this pertains to that if you are savvy on my current project.

i am at the point where i need to fill in the puzzle with random letters everywhere that there is '.' still left. (yes i am almost done!)

I think the best way to do this is to generate a pseudo random number to mod by 26 so as to stay in the alphabet and to use the askii value of whatever number is generated...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include<time.h>
using namespace std;

int main()
{
	char yorn;
	char askiichar;
	srand(unsigned (time(NULL))); 
	do{
	askiichar=(rand() % 26 + 1);
	cout<<askiichar;
	cin >>yorn;
	}while (yorn == 'y'||yorn == 'Y');
	return 0;
}

this is what i tried as a test... it generates random non-alpha/numeric characters though...

I need it to output random capitol letters. how can i achieve this?
At line 11: askiichar=((rand() % 26) + 'A');
Last edited on
i will try and see if it works can you explain why though?
It does work... is it because you are adding the 'A' ascii number to the the number between 1 and 26 so as to result in a number between 'A' and 'Z' i dont know if that makes sense i really wanna learn though : ]

*edit: I think that must be the reason. Thanks for the help!!!
Last edited on
Topic archived. No new replies allowed.