我想要一个自动填充随机字母而不重复任何字母的向量,但每当我编译程序时,它会在相同位置生成相同的字母
这是我的代码:
string alphabet[27] = { "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"};
string vector[20];
int pos[20];
int r;
bool rep = false;
int main() {
cout << "Generate vector" << endl;
for (int i = 0; i < 20; i++) {
do {
rep = false;
r = rand() % 27;
vector[i] = alphabet[r];
pos[i] = r;
for (int j = 0; j < i; j++) {
if (r == pos[j])
rep= true;
}
} while (rep == true);
}
for (int i = 0; i < 20; i++) {
cout << i << " . " << vector[i] << endl;
}
_getch();
return 0;
}