May 10, 2014 at 6:53am
Hi guys, im doing a game, which needs to repeat at least 26 times, once for each letter of the abc, which needs to be random every time.
I got this, but is not working, it gives me random char, but they are repeating...
this is my code..
1 2 3 4 5 6 7 8 9 10 11 12 13
|
srand(time(NULL));
var.letra = 97 + rand()%(122-97);
for(i=0;i<27;i++){
while(var.temp[i] == var.letra){
var.letra= 97 + rand()%(122-97);
}
}
for(i=0;i<=partidas;i++){
if(i==partidas){
var.temp[i] = var.letra;
}
}
|
thanks in advance
Last edited on May 10, 2014 at 7:35am
May 10, 2014 at 8:38am
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
|
string x = "abcdefghijklmnopqrstuvwxyz";
int inc = 26;
while (1){
if (inc < 1){
cout << "end of blah blah";
break;
}
int Number = rand() % inc + 0;
cout << x.at(Number) << endl;
string x2 = "";
for (const auto c : x){
if (c != x.at(Number)){
x2.push_back(c);
}
}
x = x2;
--inc;
}
|
Last edited on May 10, 2014 at 8:40am