-
random character
hi all,
im a newbie of c++ & struggling with a socket programming assignment. my assignment requie me to generate 4 random char with "\" after it
eg: char msgsent[1000]={"asdk\","ngwq\","utre\"............}
i need to generate 1000 set of it. is there a smarter way to generate it using C++ instead of manually set??
all these set of "data" need to send across to a server thru SEND().
Please help here..... thanks alot.
-
First I would make an array populated with letters.
Then set a random seed using srand(time())
Then in a loop, get a random number( using rand() ). Mod that number by the length of your array. That result will be the index to get a character.
Did that make any sense?
gorshing
newb
-
if you're not wary of using STL (your shouldn't be!), you can use the random_shuffle() algorithm:
http://gethelp.devx.com/techtips/cpp.../10min1299.asp
Notice the "Using random_shuffle() with Built-in Arrays" section.
Danny Kalev
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks