Hello gang!
I have another thought provoking question about a C++ program I have designed.
I have made a C++ program in which it uses a switch case statement along with a seeded PRNG to make a random string of symbols, integers, and letters. I want to store the random string in a file, but I need to store the strings in a variable. My code shown below:
srand((unsigned)time(0));
int bit=rand() % 9 + 1;
cout << "Random string: ";
switch (bit){
case 1:
cout << "S" << rand() % 99999 << "/" << rand() % 999999 <<"A~D" << "\n" ;
break;
case 2:
cout << "PoP" << rand() % 99999 << "7(Y" << rand() % 99999 << "\n" ;
break;
case 3:
cout << rand() % 99999 << "Tk-i" << rand() % 99999<< "\n" ;
break;
case 4:
cout << "&" << rand() % 99999 << "V" << rand() % 99999 <<"#W"<<"\n" ;
break;
case 5:
cout << "@R" << rand() % 99999 << rand() % 99999 <<"yK"<< "\n" ;
break;
case 6:
cout << rand() % 99999 << "PhP/d" << rand() % 99999<< "\n" ;
break;
case 7:
cout << rand() % 99999 <<"J" << rand() % 99999 <<"Fl"<< "\n" ;
break;
case 8:
cout << rand() % 99999 << ";" << rand() % 99999 <<"W!-]" << "\n" ;
break;
case 9:
cout << "*Q" << rand() % 99999 << "mR=" << rand() % 99999 << "\n" ;
break;
default:
cout << "String could not be generated because the default switch was reached." <<bit;
break;
}
ofstream a_file("Random strings.txt",ios::app);
Is there anyway to possibly store the random string in a variable so I could write out the string into a file? Anybody's thoughts would be extremely helpful!
Thanks in advance!
Tech2011
I have another thought provoking question about a C++ program I have designed.
I have made a C++ program in which it uses a switch case statement along with a seeded PRNG to make a random string of symbols, integers, and letters. I want to store the random string in a file, but I need to store the strings in a variable. My code shown below:
srand((unsigned)time(0));
int bit=rand() % 9 + 1;
cout << "Random string: ";
switch (bit){
case 1:
cout << "S" << rand() % 99999 << "/" << rand() % 999999 <<"A~D" << "\n" ;
break;
case 2:
cout << "PoP" << rand() % 99999 << "7(Y" << rand() % 99999 << "\n" ;
break;
case 3:
cout << rand() % 99999 << "Tk-i" << rand() % 99999<< "\n" ;
break;
case 4:
cout << "&" << rand() % 99999 << "V" << rand() % 99999 <<"#W"<<"\n" ;
break;
case 5:
cout << "@R" << rand() % 99999 << rand() % 99999 <<"yK"<< "\n" ;
break;
case 6:
cout << rand() % 99999 << "PhP/d" << rand() % 99999<< "\n" ;
break;
case 7:
cout << rand() % 99999 <<"J" << rand() % 99999 <<"Fl"<< "\n" ;
break;
case 8:
cout << rand() % 99999 << ";" << rand() % 99999 <<"W!-]" << "\n" ;
break;
case 9:
cout << "*Q" << rand() % 99999 << "mR=" << rand() % 99999 << "\n" ;
break;
default:
cout << "String could not be generated because the default switch was reached." <<bit;
break;
}
ofstream a_file("Random strings.txt",ios::app);
Is there anyway to possibly store the random string in a variable so I could write out the string into a file? Anybody's thoughts would be extremely helpful!
Thanks in advance!
Tech2011