473,773 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# loop for mail body generation

3 New Member
I was wondering if anyone could possibly assist me please. I'm going to come out and say I am not a C# dev and have limited knowledge on the subject but I am starting to learn it.

I being developing a mail generation tool to pump dummy mail into an exchange environment for testing purposes. Everything works beautifully and the mail generation is grand but another requirement has come up where they want valid words (doesn't have to be legible, but searchable, thus valid English words).

The list of words is not my issue, previously I was using the ascii table to produce garbled text, so now I have stipulated the list ie:

List<string> dictionary = new List<string>();
dictionary.Add( "Hello");
dictionary.Add( "great");
dictionary.Add( "perfect");
dictionary.Add( "pounding") ;
dictionary.Add( "help");

Now what I cant seem to get right is populating the email body with a random selection of these words with random paragraphs and sentences in random lengths. The above list is just a short version for testing, i have 500 plus words that will be used.

I did look at using the loop of for or foreach but, I am failing miserably.

If anyone could assist me or point me in the right direction I would greatly appreciate it.
Feb 9 '09 #1
3 3015
Plater
7,872 Recognized Expert Expert
Do the sentances make sense or can they be like:
"Hello pencil angry perfect great"?
If so you can just use a random number generator.
Generate a random number for the number of words in a sentance
rndWords=X
then do a for loop X amount of times, generating X amount of random numbers, these numbers should fall withen the range of your dictionary collection as indexes.
Does that work for you?
Feb 9 '09 #2
pierrej
3 New Member
That would work perfectly, making sense is no requirement at all.
Just that the data needs to be searchable, thus the requirement for valid words.

So yes that should work nicely.
Feb 9 '09 #3
vekipeki
229 Recognized Expert New Member
You could use the Random class to generate a random index for your List of strings in a loop:

Expand|Select|Wrap|Line Numbers
  1. const int totalNumberOfWords = 100;
  2. int count = 0;
  3.  
  4. StringBuilder sb = new StringBuilder();
  5. Random rnd = new Random();
  6.  
  7. while (count < totalNumberOfWords)
  8. {
  9.     // get a random word index
  10.     int randomIndex = rnd.Next(dictionary.Count);
  11.  
  12.     // append the word
  13.     sb.Append(dictionary[randomIndex]);
  14.  
  15.     // append a space
  16.     sb.Append(" ");
  17.  
  18.     // next word
  19.     count++;
  20. }
You can also use the Random class to create sentences and paragraphs every once in a while. If you presume that the random generator creates randomly distributed numbers, then you can check (for example) if a rnd.NextDouble( ) returns a number greater than 0.95 - this should happen with 5% probability - and if yes, add a new line (or a dot to the StringBuilder).

Spammers use Markov chain algorithms to generate pseudo-random texts, based on some input data, so if you need your text to have at least some structure, you might try to Google it.

EDIT: Ooops, sorry - I just saw previous posts.
Feb 9 '09 #4

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

Similar topics

0
2559
by: Kingdom | last post by:
I Need some serious help here. strugling novis with ASP and javascript any help would be greatly appreciated The script below does exactly what I want it to do for each product on the two passes it makes however I would like the entire script to loop 34 times and on each of those 30 loops also write the product and the price (only) onto the page building a compleate list of all the products selected over the 34 loops ending with a total...
6
11188
by: DigitalRick | last post by:
I have been running CDONTS in my ASPpages to send emails to me sent from my guestbook. It had been working fine untill I upgraded to Server 2003 (I am also running Exchange 2003) all locally. I will include the code I originally used. I understand I should switch from CDONTS to CDO mail but after several sttempts I am finding a very hard time getting the new CDO mail to work properly. Any assistance with this would be greatly...
32
4658
by: Toby Newman | last post by:
At the page: http://www.strath.ac.uk/IT/Docs/Ccourse/subsection3_8_3.html#SECTION0008300000000000000 or http://tinyurl.com/4ptzs the author warns: "The for loop is frequently used, usually where the loop will be traversed a fixed number of times. It is very flexible, and novice programmers should take care not to abuse the power it offers."
22
2229
by: Jan Richter | last post by:
Hi there, the Code below shows DJBs own implementation of strlen (str_len): unsigned int str_len(char *s) { register char *t; t = s; for (;;) { if (!*t) return t - s; ++t;
4
1674
by: D. Shane Fowlkes | last post by:
I've decided to send weekly emails to registered users ("members") on one of my sites. This will be the first time I attempted anything like this. Now I know I could use some 3rd party list server services like MailChimp.com or ConstantContact.com but since this site I have is basically maintained and developed for free, I want to keep my overhead as low as possible. Before I actually dive into this and build one from scratch, is there...
5
1359
by: Brian | last post by:
void generation_loop() { int generation = 1; double x = 0.25; double y = 0.50; double z = 0.25; double AA, AB, BB; double p = (y/(y+z))/2; AA = pow(p,2); AB = 2*p*(1-p);
3
1865
by: Camel | last post by:
I am very new to C++ and came across this section of code in an example, whilst learning about dynamic memory. The example uses the delete operator in a for loop, it seems to imply that each time the loop runs the memory for the array will be deleted. I don't think this is correct. Can someone offer me an explanation as to why this code works? I have only included the section which includes the for loop and the delete operator.
2
2674
by: Ruud | last post by:
Just before leaving for a holiday my collegue modified this script. Now it won't send any body text (The data filled in on the form) and in an error condition it won't send any attachments either. Because I don't understand PHP I cannot find the error. Who is willing to help? regards Ruud
14
1805
by: Jeff | last post by:
I'm writing my php "form mail" script. Does mail do any checking for header injection in the "to" and "subject" parameters? CR and/or LF? It seems to me it easily could and should, but does it? Jeff
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.