Home / utk / cs102 / fa16 / labe / code_snippets / randchar_example.cpp
Directory Listing
function_example.cpp
randchar_example.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

//consts

char rand_gen();

int main() {
	int seed, length;

	cout << "Enter seed: ";
	cin >> seed;
	srand(seed);
	cout << "Enter password length: ";
	cin >> length;
	
	if (length < 1 ) length = 1;
	if (length > 25) length = 25;

	//Output password one character at a time
	for (int i = 0; i < length; i++) {
		cout << rand_gen();
	}
	cout << endl;
}

char rand_gen() {
	//returns random character
	return 'A' + (rand() % 26);
}