468,491 Members | 1,916 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

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
Oct 20 '06 #1
7 3286
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
Oct 20 '06 #2
arne
315 Expert 100+
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

Expand|Select|Wrap|Line Numbers
  1.     for( int i=0; i<1024; i++ ) {
  2.  
  3.         cout << rand() << endl;
  4.     }
  5.  
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?
Oct 20 '06 #3
Thanks for ur replay
pls help me how to generate string(character)
by using rand() i able to generate only numbers,
how to generate random characters.
pls help me.


thank you,
Oct 26 '06 #4
arne
315 Expert 100+
Thanks for ur replay
pls help me how to generate string(character)
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 ...
Oct 26 '06 #5
Pls can u give me one example
I am now learning VC,
idont know much about this,


Thankyou,
Oct 27 '06 #6
arne
315 Expert 100+
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:

Expand|Select|Wrap|Line Numbers
  1. int ic;
  2. ic = 65 + (rand() % 26);
  3. cout << (char)ic << endl;
  4.  
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 :)
Oct 27 '06 #7
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
Oct 27 '06 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Joseph | last post: by
reply views Thread by zhimin | last post: by
17 posts views Thread by Sri | last post: by
15 posts views Thread by Orchid | last post: by
9 posts views Thread by Omatase | last post: by
3 posts views Thread by gieforce | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.