Random numbers
-
hi! I am using the following code to generate a random string. But each time i get the same string output. Can anyone help. char myarray[22]; char* CGeneratorApp::GenerateString() { myarray[21]='\0'; for(int k=0;k<21;k++) { myarray[k] = (char)(((int)rand()%25)+65); } char first[2]; intUsed++; sprintf(first,"%d",intUsed); if(intUsed<10) { first[1]=first[0]; first[0]='0'; } first[0]=(char)((int)first[0]+27); first[1]=(char)((int)first[1]+27); myarray[8]=first[0]; myarray[10]=first[1]; AfxMessageBox(myarray); return myarray; } Thnx in advance
-
hi! I am using the following code to generate a random string. But each time i get the same string output. Can anyone help. char myarray[22]; char* CGeneratorApp::GenerateString() { myarray[21]='\0'; for(int k=0;k<21;k++) { myarray[k] = (char)(((int)rand()%25)+65); } char first[2]; intUsed++; sprintf(first,"%d",intUsed); if(intUsed<10) { first[1]=first[0]; first[0]='0'; } first[0]=(char)((int)first[0]+27); first[1]=(char)((int)first[1]+27); myarray[8]=first[0]; myarray[10]=first[1]; AfxMessageBox(myarray); return myarray; } Thnx in advance
Please take a look into the MSDN under command 'srand' !!! Try to extend your code as follow: #include #include .. ... srand ( (unsigned)time (NULL) ); for(int k=0;k<21;k++) { myarray[k] = (char)(((int)rand()%25)+65); } ... ... greets al
-
Please take a look into the MSDN under command 'srand' !!! Try to extend your code as follow: #include #include .. ... srand ( (unsigned)time (NULL) ); for(int k=0;k<21;k++) { myarray[k] = (char)(((int)rand()%25)+65); } ... ... greets al
Dont forget to call randomize before calling the rand fucntion.
1.Why do people not wearing a wrist watch look at their wrist for time when people ask for time. 2.Why do people ask for time from people who are not wearing a wrist watch. Prakash, India.
-
Please take a look into the MSDN under command 'srand' !!! Try to extend your code as follow: #include #include .. ... srand ( (unsigned)time (NULL) ); for(int k=0;k<21;k++) { myarray[k] = (char)(((int)rand()%25)+65); } ... ... greets al
sorry, the includes are: :-D #include #include greets al
-
Please take a look into the MSDN under command 'srand' !!! Try to extend your code as follow: #include #include .. ... srand ( (unsigned)time (NULL) ); for(int k=0;k<21;k++) { myarray[k] = (char)(((int)rand()%25)+65); } ... ... greets al
it works thnx