How to Generate a large length of strings/numbers eg 4k byte

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anitha1234
    New Member
    • Oct 2006
    • 8

    How to Generate a large length of strings/numbers eg 4k byte

    In C++ by using rand(); i am able to generate 10 numbers,
    if i want to generate 4kbytes of numbers or strings
    what i have to do, if anyone knows pls help me.
    Thankyou
  • renjicom
    New Member
    • Oct 2006
    • 1

    #2
    Originally posted by anitha1234
    In C++ by using rand(); i am able to generate 10 numbers,
    if i want to generate 4kbytes of numbers or strings
    what i have to do, if anyone knows pls help me.
    Thankyou
    U plz refer about Hashing algorithm It will give the solution
    It is also pointer related

    Comment

    • arne
      Recognized Expert Contributor
      • Oct 2006
      • 315

      #3
      Originally posted by anitha1234
      In C++ by using rand(); i am able to generate 10 numbers,
      if i want to generate 4kbytes of numbers or strings
      what i have to do, if anyone knows pls help me.
      Thankyou
      You may want to use a loop, like

      Code:
      	for( int i=0; i<1024; i++ ) {
      
      		cout << rand() << endl;
      	}
      This example will produce 1024 random numbers. On most systems, an int is 4 bytes long, so you have 4kBytes of random numbers in total. Is that what you would like to do?

      Comment

      • anitha1234
        New Member
        • Oct 2006
        • 8

        #4
        Thanks for ur replay
        pls help me how to generate string(characte r)
        by using rand() i able to generate only numbers,
        how to generate random characters.
        pls help me.


        thank you,

        Comment

        • arne
          Recognized Expert Contributor
          • Oct 2006
          • 315

          #5
          Originally posted by anitha1234
          Thanks for ur replay
          pls help me how to generate string(characte r)
          by using rand() i able to generate only numbers,
          how to generate random characters.
          pls help me.


          thank you,
          One possibility is to establish a mapping between your random numbers and the characters. Hint: Use the % function and remember that 'A' has ASCII value 65, 'B' has value 66, and so on ...

          Comment

          • anitha1234
            New Member
            • Oct 2006
            • 8

            #6
            Pls can u give me one example
            I am now learning VC,
            idont know much about this,


            Thankyou,

            Comment

            • arne
              Recognized Expert Contributor
              • Oct 2006
              • 315

              #7
              Originally posted by anitha1234
              Pls can u give me one example
              I am now learning VC,
              idont know much about this,


              Thankyou,
              Consider something like the following code snippet:

              Code:
              int ic;
              ic = 65 + (rand() % 26);
              cout << (char)ic << endl;
              This code defines an int called 'ic'.
              rand() % 26 delivers random numbers in the range [0,..,25].
              'ic' gets assigned such a random number plus the offset 65. So 'ic' has numbers in the rang [65, .. 90]. By casting 'ic' to a char in line 3, the program prints letters between 'A' (ASCII code 65) and 'Z' (ASCII code 90).

              Hope that helps :)

              Comment

              • anitha1234
                New Member
                • Oct 2006
                • 8

                #8
                Thank you very much for ur help,
                now i want one more help,

                I am creating a text file
                How to Save a File(text file) in VC++
                If i click the command button, save dialog box should open,
                user should give a name & save/Saveas the text file.

                By using i am able to open a OPEN DIALOG BOX
                CFIleDialog m_samp(TRUE);
                m_samp.Domodal( );
                To save or Save as How to do.



                pls help me..........


                Thanks

                Comment

                Working...