Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Random numbers

Random numbers

Scheduled Pinned Locked Moved C / C++ / MFC
helplounge
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    amit sebiz
    wrote on last edited by
    #1

    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

    E 1 Reply Last reply
    0
    • A amit sebiz

      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

      E Offline
      E Offline
      Elmar Weber
      wrote on last edited by
      #2

      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

      P E A 3 Replies Last reply
      0
      • E Elmar Weber

        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

        P Offline
        P Offline
        Prakash Nadar
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • E Elmar Weber

          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

          E Offline
          E Offline
          Elmar Weber
          wrote on last edited by
          #4

          sorry, the includes are: :-D #include #include greets al

          1 Reply Last reply
          0
          • E Elmar Weber

            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

            A Offline
            A Offline
            amit sebiz
            wrote on last edited by
            #5

            it works thnx

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups