Hello all, I am new to this site and I am in need of some advice. I am trying to create a random sentence generator for a project that I have started and I would like to know if anyone has any suggestions, references, experience, or examples that could help me in any way. I have a background in HTML and CSS, and I have dabbled in Python and PHP, but I am admittedly rusty and do not mind starting with beginner material. Any input would be greatly appreciative. Thanks.
4 replies to this topic
#1
Posted 29 September 2010 - 09:14 PM
|
|
|
#2
Posted 29 September 2010 - 10:02 PM
Hmmm.... you could use a list of nouns, verbs etc. and then create sentences using a random number that chooses the words from your list. That's the easiest approach I can imagine. Most probably there are many better methods. So just use Google or wait till the other members give you advice.
Greets,
artificial
Greets,
artificial
Sometimes words ain't enough to express something. That's why computer scientists use double words.
#3
Posted 29 September 2010 - 10:21 PM
I would do it in C++ ( as it is the greatest language in existence :-P ). I would create an array of words then use a random number generator in the appropriate range relative to the array to pick a value( use randomly generated number as index ). Append returned index to the string, i would recommend using a loop unless you have some other trick you can use
#4
Posted 01 October 2010 - 09:15 AM
Make sure you code the random word generator so that it does not produce an unreadable sentence, unless that actually is your intention. Have it first generate the noun and then the verb. If necessary, generate an adverb or adjective too. So, one way to do it would to append the string after each part is generated. For example (in Python):
import random nouns = ["The dog", "The cat"] verbs = ["ate food.", "pooped in the grass."] sentence = "" sentence = nouns[random.randrange(0,1)] + " " + verbs[random.randrange(0,1)] print sentence
Edited by daniel-lemke, 01 October 2010 - 05:04 PM.
#5
Posted 01 October 2010 - 01:43 PM
I'd create standard sentence formats, something like
[Subject] [Verb]
[Adjective] [Subject][Verb]
[Subject] [Verb] [Object]
Hopefully you get the idea. Then have lists of words for each sentence part, pick a sentence format at random and pick the parts from your lists.
[Subject] [Verb]
[Adjective] [Subject][Verb]
[Subject] [Verb] [Object]
Hopefully you get the idea. Then have lists of words for each sentence part, pick a sentence format at random and pick the parts from your lists.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









