Jump to content

Urgent Advice Needed

- - - - -

  • Please log in to reply
4 replies to this topic

#1
chris_silas

chris_silas

    Newbie

  • Members
  • Pip
  • 1 posts
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.

#2
artificial

artificial

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 624 posts
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
Sometimes words ain't enough to express something. That's why computer scientists use double words.

#3
untitled_1

untitled_1

    Learning Programmer

  • Members
  • PipPipPip
  • 89 posts
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
mrlemke

mrlemke

    Learning Programmer

  • Members
  • PipPipPip
  • 68 posts
  • Location:Redding, CA
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
Momerath

Momerath

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 243 posts
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.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users