CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2014
    Posts
    1

    Exclamation Random Word generator to create sentance

    I am having a hard time finding some code to make a random word generator. I want the user to be able to click a button, and have a randomly generated sentance of the words (3 or more), with mabye the possibility to choose how many words the sentance has.

    =Can anyone help me out?

    I am trying to use this wordlist.


    Ticket","Horse","Rope","Scale","Fan","Sack","Sausage","Scale","Seal","School","Saw","Palace","Flag","Tent","Ear","Text","Eye","Stamp","Gloves","Gun","Grass","Sword","Ditch","

    Dove","Duck","Panda","Wire","Netting","Pistol","Coin","Cow","Flute","Spoon","Ice","Key","Knife","Watermelon","Socks","Verse","Rain","Brick","Cabbage","Camel","Cat","Leaf","Shee

    t","Stone","Street","Work","Tounge","Tool","Thunder","Rice","Chain","Chalk","Word","Wood","Chess","Spade","Lotus","Root","Story","Sheep","Stool","Bean","Curd","Chopsticks","Roc

    ket","Room","Steamed","Breed","Luggage","Ship","Rubbish","Beefsteak","Article","Troops","Black","Shoes","Map","Match","Skirt","Melon","Ship","Meat","Boxx","Well","Shop","Book",

    "Bone","Tooth","Toothpaste","Rope","Road","Tractor","Bear","Beer","Abacus","Tower","Wharf","Arm","Arrow","Watch","Mooncake","Cake","Tree","Rubber","Axe","River","Nail","Basket"

    ,"Bank","Wall","Mountain","Mouth","Mouse","Muffler","Mud","Train","Nose"



    Thankyou!

    -Neil

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Random Word generator to create sentance

    What language are you using?

    You could have a text file containing the words (so you can change the words without recompiling) which is read into a container such as a vector (c++) and then have a loop generating a random number between 0 and the number of the words read less one that indexes into the container to obtain the random word. The loop would control how many words are generated for the sentence. Using just these words won't generate a 'proper' sentence though.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured