473,387 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C# loop for mail body generation

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 2985
Plater
7,872 Expert 4TB
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
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 Expert 100+
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
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...
6
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...
32
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...
22
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
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...
5
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
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...
2
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....
14
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?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.