1.

Solve : Choosing random words?

Answer»

How would you choose a random word from 'lists' of words?

For example...

List number one will be:
-He
-She
-It

List number two:
-swam
-jumped
-screamed

It will PICK one random word from list number one.
On the second list...

If the word 'swam' is chosen it goes to a list specified list for 'swam'.
For example, if 'swam' is chosen, the next random word will be either:
-fast
-slow
-proudly

If 'jumped' is chosen, the next random word will be either:
-high
-far
-low

If 'screamed' is chosen, the next random word will be either:
-loud
-quietly
-uncontrollably

Then in the end it will put the words together such as...

She jumped high.

Just an example ^,  but I'm wondering how i can do this.  Thanks
So, what you'll first need is a file with a list of words, in my code it will be called TOPlist.txt . Then, for each word in any list, you need a file called WORDlist.txt (word being substituted for the actual word).

The script will only display the sentence when it has reached a word with no sub-list.

Code: [Select]echo off
setlocal enabledelayedexpansion
set rnd=0
set word0=TOP
:loop
If exist !word%rnd%!list.txt (
call :words
goto loop
) else (
echo %display%
pause
)
exit

:words
set count=0
for /f "delims=" %%A in (!word%rnd%!list.txt) do (
set word!count!=%%A
set /a count+=1
)
set /a rnd=%random%%%%count%
set display=%display%!word%rnd%! How does reply 1 or reply 2 help? Quote from: Frankfoley on December 20, 2010, 06:39:58 AM

How does reply 1 or reply 2 help?
How does making posts like that help? I gave a code which should help the OP. Quote from: Helpmeh on December 20, 2010, 07:57:52 AM
How does making posts like that help? I gave a code which should help the OP.

Helpmeh: It's Bill again. Quote from: BC_Programmer on December 20, 2010, 07:59:37 AM
Helpmeh: It's Bill again.

He is always easy to spot.
An alternative... a limitation is that for the adverbs, you have to have the same number for each verb. Also, a grammar point, in the examples given, "slow" and "loud" are incorrect in standard English - they are verbs, the correct adverbs are slowly and loudly.

Code: [Select]echo off
setlocal enabledelayedexpansion

rem I know He, It, They are pronouns; it makes the code simpler
rem if I call them nouns here
rem noun He
rem noun It
rem noun She
rem noun John
rem noun Mary
rem noun They
rem 5 nouns or pronouns


rem verb swam
rem verb jumped
rem verb screamed
rem verb walked
rem verb smiled
rem 5 verbs

rem adverb swam fast
rem adverb swam slowly
rem adverb swam proudly
rem adverb swam WELL
rem adverb swam badly

rem adverb jumped high
rem adverb jumped far
rem adverb jumped low
rem adverb jumped up
rem adverb jumped down

rem adverb screamed loudly             
rem adverb screamed quietly       
rem adverb screamed uncontrollably
rem adverb screamed instantly
rem adverb screamed alarmingly

rem adverb walked quickly
rem adverb walked strangely
rem adverb walked often
rem adverb walked seldom
rem adverb walked briskly

rem adverb smiled sweetly
rem adverb smiled readily
rem adverb smiled dourly
rem adverb smiled oddly
rem adverb smiled happily
rem 5 adverbs for each verb

set /a nrand=%random%%%5+1
set /a vrand=%random%%%5+1
set /a arand=%random%%%5+1

set number=1
for /f "tokens=1-3 delims= " %%N in ( ' type "%0" ^| find "rem noun" ^| find /v "type" ' ) do (
if !number! equ %nrand% set noun=%%P
set /a number+=1
)
set number=1
for /f "tokens=1-3 delims= " %%V in ( ' type "%0" ^| find "rem verb" ^| find /v "type" ' ) do (
if !number! equ %vrand% set verb=%%X
set /a number+=1
)
set number=1
for /f "tokens=1-4 delims= " %%A in ( ' type "%0" ^| find "rem adverb %verb%" ^| find /v "type" ' ) do (
if !number! equ %arand% set adverb=%%D
set /a number+=1
)
set phrase=%noun%%verb%%adverb%
echo %phrase%

Code: [Select]S:\Test\random-word>for /l %Q in (1,1,30) do rand-phrase.bat
John screamed loudly
John screamed uncontrollably
Mary screamed alarmingly
He swam fast
Mary swam well
She swam well
John smiled oddly
John swam proudly
He smiled oddly
She jumped high
Mary walked quickly
She walked seldom
He screamed loudly
She jumped far
It jumped down
Mary swam well
It walked seldom
It smiled sweetly
It walked quickly
She swam badly
John smiled dourly
John swam well
She walked often
She jumped up
It walked strangely
She screamed alarmingly
She smiled sweetly
She screamed loudly
It jumped up
It smiled dourlySalmon Trout, The Sockpuppet, strikes again.

Always easy to spot.


Salmon Trout and Shanked  are the same person
Quote from: Helpmeh on December 20, 2010, 07:57:52 AM
I gave a code which should help the OP.

How does your code  help? Your code generates no output.  Your code does nothing.

Look at Samon Trout's code for the answer.oh Bill, you crazy insane fool.

See people, this is what FORTRAN does to people. Dijkstra noted that BASIC mutilated minds but apparently so too does long time exposure to FORTRAN.


Quote from: bobhoward on December 20, 2010, 12:05:00 PM
How does your code  help? Your code generates no output.  Your code does nothing.

His code works fine. Perhaps you didn't read the instructions. Not that it matters, you clearly cannot read the various hints by the forum to go away, such as, for example, being banned countless number of times.

preemptive response fro Bill; will probably be something to the effect of apologizing to the OP for his thread going off topic and then wishing him well getting help, or some other completely random muttering. Possibly accompanied by asking me where my code for this issue is. Quote from: BC_Programmer on December 20, 2010, 12:16:23 PM

His code works fine. Perhaps you didn't read the instructions.

preemptive response fro Bill; will probably be something to the effect of apologizing to the OP for his thread going off topic and then wishing him well getting help, or some other completely random muttering. Possibly accompanied by asking me where my code for this issue is.

To:
BC, The Computer Dilettante who has  never had a creative thought in his life.

Thanks for the help.

Please provide the output for Helpmeh's codeOuch! My precious feelings! Oh how will I ever recover from the death blow that the great Bill has caused to my ego.

Although the fact that simple directions cannot be followed, and he is essentially asking me to perform the very simple, grade-school task of following some of the relatively simple STEPS that Helpmeh provides for running his scripts sort of ruins the ATTEMPT at an insult.

Better luck next time perhaps.

Quote from: bobhoward on December 20, 2010, 12:05:00 PM
Your code generates no output.

Bill is crazier than a whole barrel of Tea Party members.
Quote from: BC_Programmer on December 20, 2010, 12:43:18 PM
Although the fact that simple directions cannot be followed, and he is essentially asking me to perform the very simple, grade-school task of following some of the relatively simple steps that Helpmeh provides for running his scripts sort of ruins the attempt at an insult.


BC, The Computer Dilettante:

Where is Helpmeh's code and output?  Some the readers here are gradeschool children and new to computers.

Not  only is BC a Computer Dilettante but BC is an expert at evasion, double talk and long nonsense posts.
Code: [Select]D:\testhm>runhm

-----------------------------
atelist.txt:
-----------------------------
quickly
deliberately
-----------------------------
helist.txt:
-----------------------------
Ate
Left
-----------------------------
jumpedlist.txt:
-----------------------------
quickly

-----------------------------
leftlist.txt:
-----------------------------
quickly
deliberately
-----------------------------
shelist.txt:
-----------------------------
jumped
slowly
-----------------------------
slowlylist.txt:
-----------------------------
ate
left
-----------------------------
TOPlist.txt:
-----------------------------
He
She
Result:
He Left quickly

D:\testhm>

also:

Quote
BC, The Computer Dilettante:

That shouldn't be capitalized; it should be "BC, the computer dilettante".

oh yes, Should post the runhm.bat program as well:


Code: [Select]echo off
for %%P in (*.txt) do (
echo.
echo -----------------------------
echo %%P:
echo -----------------------------
type %%P
)
echo.
echo Result:
echo.
hm




Discussion

No Comment Found