Can't seem to make random number generator generate random accuracy?

Have you sometimes ever hear that beep sound in your ear? and the myth is when you hear a "BEEP" that means someone is talking about you, rather it is real or not, your suppose to have someone guess a number from 1 - 26, and what ever the number that the person gave you, you find the the letter of it. Example: the person said 3, so that means someone who starts with the letter "C" was talking about you or 1 then it is letter "A". So, yea, what ever anyways, that's what my program is suppose to do, but UNFORTUNATELY it keeps displaying the same letter "K". Maybe it can be the do-while-loop? or the way I assigned random being int iRandom(0+rand()%27) or I don't know? I switched the 0 to 1 and the only difference was instead of "K" being displayed, "L" was only displaying.

Here is my code:
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <iostream>
#include <ctime>
#include <cstdlib>
/*By the way, does it really matter if I include cstdlib?
I noticed without the header file random numbers can still be generated*/
#include <Windows.h>
#include <string>

void cleanUp(void);

class PeoplesFirstLetterName {
protected:
	char a, b, c, d, e, f, g, h, i, j, k ,l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

public:
	PeoplesFirstLetterName
		(char setA=('A'), char setB=('B'), char setC=('C'), char setD=('D'), char setE=('E'), char setF=('F'),
		 char setG=('G'), char setH=('H'), char setI=('I'), char setJ=('J'), char setK=('K'), char setL=('L'),
		 char setM=('M'), char setN=('N'), char setO=('O'), char setP=('P'), char setQ=('Q'), char setR=('R'),
		 char setS=('S'), char setT=('T'), char setU=('U'), char setV=('V'), char setW=('W'), char setX=('X'),
		 char setY=('Y'), char setZ=('Z')) {
			 a=setA, b=setB, c=setC, d=setD, e=setE, f=setF, g=setG, h=setH, i=setI, j=setJ, k=setK, l=setL,
				 m=setM, n=setN, o=setO, p=setP, q=setQ, r=setR, s=setS, t=setT, u=setU, v=setV, w=setW, x=setX,
				 y=setY, z=setZ;
	}
};

class FirstLetters : public PeoplesFirstLetterName {
public:
	void letterA() {std::cout<<("Someone with the Letter: ")<<(a)<<("\nis talking about you")<<std::endl;};
	void letterB() {std::cout<<("Someone with the Letter: ")<<(b)<<("\nis talking about you")<<std::endl;};
	void letterC() {std::cout<<("Someone with the Letter: ")<<(c)<<("\nis talking about you")<<std::endl;};
	void letterD() {std::cout<<("Someone with the Letter: ")<<(d)<<("\nis talking about you")<<std::endl;};
	void letterE() {std::cout<<("Someone with the Letter: ")<<(e)<<("\nis talking about you")<<std::endl;};
	void letterF() {std::cout<<("Someone with the Letter: ")<<(f)<<("\nis talking about you")<<std::endl;};
	void letterG() {std::cout<<("Someone with the Letter: ")<<(g)<<("\nis talking about you")<<std::endl;};
	void letterH() {std::cout<<("Someone with the Letter: ")<<(h)<<("\nis talking about you")<<std::endl;};
	void letterI() {std::cout<<("Someone with the Letter: ")<<(i)<<("\nis talking about you")<<std::endl;};
	void letterJ() {std::cout<<("Someone with the Letter: ")<<(j)<<("\nis talking about you")<<std::endl;};
	void letterK() {std::cout<<("Someone with the Letter: ")<<(k)<<("\nis talking about you")<<std::endl;};
	void letterL() {std::cout<<("Someone with the Letter: ")<<(l)<<("\nis talking about you")<<std::endl;};
	void letterM() {std::cout<<("Someone with the Letter: ")<<(m)<<("\nis talking about you")<<std::endl;};
	void letterN() {std::cout<<("Someone with the Letter: ")<<(n)<<("\nis talking about you")<<std::endl;};
	void letterO() {std::cout<<("Someone with the Letter: ")<<(o)<<("\nis talking about you")<<std::endl;};
	void letterP() {std::cout<<("Someone with the Letter: ")<<(p)<<("\nis talking about you")<<std::endl;};
	void letterQ() {std::cout<<("Someone with the Letter: ")<<(q)<<("\nis talking about you")<<std::endl;};
	void letterR() {std::cout<<("Someone with the Letter: ")<<(r)<<("\nis talking about you")<<std::endl;};
	void letterS() {std::cout<<("Someone with the Letter: ")<<(s)<<("\nis talking about you")<<std::endl;};
	void letterT() {std::cout<<("Someone with the Letter: ")<<(t)<<("\nis talking about you")<<std::endl;};
	void letterU() {std::cout<<("Someone with the Letter: ")<<(u)<<("\nis talking about you")<<std::endl;};
	void letterV() {std::cout<<("Someone with the Letter: ")<<(v)<<("\nis talking about you")<<std::endl;};
	void letterW() {std::cout<<("Someone with the Letter: ")<<(w)<<("\nis talking about you")<<std::endl;};
	void letterX() {std::cout<<("Someone with the Letter: ")<<(x)<<("\nis talking about you")<<std::endl;};
	void letterY() {std::cout<<("Someone with the Letter: ")<<(y)<<("\nis talking about you")<<std::endl;};
	void letterZ() {std::cout<<("Someone with the Letter: ")<<(z)<<("\nis talking about you")<<std::endl;};
};

void menu() {
	std::string tab(6,('\t')), tab1(4,('\t')), tab2(5,('\t')), underScores(80,('_'));
	std::cout<<("Who is talking about you?")<<(tab)<<("\b[FindOut]")
		<<(underScores)<<(tab1)<<("\b\bType in<[ who ]>to begin")<<std::endl
		<<std::endl
		<<(tab2)<<("\b:> ");
}

int main() {
	FirstLetters expose;
	
	srand(NULL(time));
	int iRandom(0+rand()%27);

	bool dontExit(false);

	menu();

	std::string input;

	do {
		std::cin>>input;

		if (input == ("who")) {
			if (iRandom == 1) {
				expose.letterA();
			} else if (iRandom == 2) {
				expose.letterB();
			} else if (iRandom == 3) {
				expose.letterC();
			} else if (iRandom == 4) {
				expose.letterD();
			} else if (iRandom == 5) {
				expose.letterE();
			} else if (iRandom == 6) {
				expose.letterF();
			} else if (iRandom == 7) {
				expose.letterG();
			} else if (iRandom == 8) {
				expose.letterH();
			} else if (iRandom == 9) {
				expose.letterI();
			} else if (iRandom == 10) {
				expose.letterJ();
			} else if (iRandom == 11) {
				expose.letterK();
			} else if (iRandom == 12) {
				expose.letterL();
			} else if (iRandom == 13) {
				expose.letterM();
			} else if (iRandom == 14) {
				expose.letterN();
			} else if (iRandom == 15) {
				expose.letterO();
			} else if (iRandom == 16) {
				expose.letterP();
			} else if (iRandom == 17) {
				expose.letterQ();
			} else if (iRandom == 18) {
				expose.letterR();
			} else if (iRandom == 19) {
				expose.letterS();
			} else if (iRandom == 20) {
				expose.letterT();
			} else if (iRandom == 21) {
				expose.letterU();
			} else if (iRandom == 22) {
				expose.letterV();
			} else if (iRandom == 23) {
				expose.letterW();
			} else if (iRandom == 24) {
				expose.letterX();
			} else if (iRandom == 25) {
				expose.letterY();
			} else if (iRandom == 26) {
				expose.letterZ();
			}
		} else {
			std::cout<<("\nInvalid Command\n");
		}

	} while(!dontExit);

	return 0;
}

void cleanUp(void) { /*FYI this is to clear, but I have not used it yet because of my issue*/
	DWORD n, size;
	COORD coord={0};
	CONSOLE_SCREEN_BUFFER_INFO csbi;
	HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
	GetConsoleScreenBufferInfo(h, &csbi);
	size = csbi.dwSize.X * csbi.dwSize.Y;
	FillConsoleOutputCharacter(h, TEXT(' '), size, coord, &n);
	GetConsoleScreenBufferInfo(h, &csbi);
	FillConsoleOutputAttribute(h, csbi.wAttributes, size, coord, &n);
	SetConsoleCursorPosition(h, coord);
}
I would expect rand() to be called in the loop, not once before you enter the loop.

You could use an array of characters to eliminate all that duplicate code.
You have your random setup wrong. You never assign it a value. Change it to int iRandom=(1+rand()%26); and the program will run correctly.
So I took kbw's advice and whitenite1's advice, still no luck. Am I doing something wrong?
I tried:
1
2
3
4
5
6
7
8
9
10
11
12
 

	do {	srand(NULL(time));
		std::cin>>input;
		
		if (input == ("who")) {
			int iRandom=(0+rand()%27); //I assigned the value
			if (iRandom == 1) {
				expose.letterA();
			} else if (iRandom == 2) {
				expose.letterB();
			} 


and another method I tried:
1
2
3
4
5
6
7
8
9
10
11
	do { 
		std::cin>>input;
		
		if (input == ("who")) {
                        srand(NULL(time));
			int iRandom=(1+rand()%27); //I assigned the value
			if (iRandom == 1) {
				expose.letterA();
			} else if (iRandom == 2) {
				expose.letterB();
			} 
just a little side note for all those functions, you could use a for loop and an array to save a ton of code and worries.
Don't move int iRandom=(1+rand()%26); into the do loop. Just replace your int iRandom(0+rand()%27);, with it.
He doesn't even need an array. They're all literal values.

1
2
3
char c = char(rand() % 26) + 'A';

std::cout<< "Someone with the Letter: " << c << "\nis talking about you" << std::endl;


Anyway, kbw's advice was to move rand to inside the loop, not srand.

srand should stay at the top. rand() should be moved to wherever you want a new random number. If you want a new random number every time the loop runs, then rand() belongs in the loop.
May you show me an example for the for loop using an array? You don't have to use my code or you can just direct me to a site. And still I can't figure out to generate random numbers, I tried so many differents techniques.
Interesting... I figured out a more simple way -_-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <ctime>

signed int holdUp();

int main() {
	srand(time(NULL));
	char letters(('A') + rand() % 26);

	std::cout<<("Someone who starts with the letter ")<<(letters)<<(" was talking about you.")<<std::endl;

	holdUp();return 0;
}

signed int holdUp() {
	std::cin.sync(),
		std::cin.ignore();
	return(0);
}
Instead of
1
2
3
4
srand(NULL(time));
I switched too
srand(time(NULL)); //Could that have been my issue? or it didn't matter?
//Because it seemed fined to me =D! 
Thank you guys for all your help!
A general rule of thumb: If you find yourself making variables like "foo1", "foo2", 'foo3", etc, then you are doing something wrong.
Disch can you be my MENTOR!? LOL
Topic archived. No new replies allowed.