-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrand_letter_gen.cpp
More file actions
49 lines (41 loc) · 1020 Bytes
/
rand_letter_gen.cpp
File metadata and controls
49 lines (41 loc) · 1020 Bytes
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
#include <iostream>
#include <math.h>
using namespace std;
int const ALPHA = 27;
int const LENGTH = 26;
int const SPACING = 5;
//* simple program to generate 10 random lower case letters *//
int main()
{
int numLetters = 0;
int index;
char alphabet[ALPHA] = "abcdefghijklmnopqrstuvwxyz";
bool selected[LENGTH];
for (int z = 1; z <= 10; z++)
{
//set to false
for (int i = 0; i < LENGTH; i++)
selected[i] = false;
index = 0;
numLetters = 0;
cout << " Permutation " << z << endl;
cout << " ============ " << endl;
for (;;)
{
index = rand() % LENGTH;
if (selected[index] == false)
{
if (numLetters % SPACING == 0) //space
cout << " ";
cout << alphabet[index];
selected[index] = true;
numLetters++;
}
if (numLetters >= 26)
break;
}
cout << "\n" << endl;
}//end outside for loop
cout << "\n" << endl;
return 0;
}