Sign in to follow this  
Followers 0
Diana (Cda)

Has anyone seen ... script to pull words from a word list?

6 posts in this topic

I can build some parts of this now, the easy parts admittedly, but was wondering if anyone has seen a script that already does something of what I need. I would like to be able to load one of any of the several word lists I have and then to specify the target number of words I'd like AutoIt to pull from the list and to send them to the clipboard.

i.e., if the word list goes something like this:

ABOLISHED

ABOLISHER

ABOLISHERS

ABOLISHES

ABOLISHING

ABOLISHMENT

ABOLISHMENTS

ABOLITION

ABOLITIONISM

ABOLITIONIST

ABOLITIONISTS

A-BOMB

... (etc. Word list has several thousands of words in it).

and I ask AutoIt to pull, say, 15 words as an example out of the list (I'd use probably on average 40-50 words), that it would pick them at random and would then deposit them onto the clipboard so that I'd get something like this (which I just did manually myself):

ELECTRONS

FUTURE

KELVIN

LECITHIN

LOWELL

PHOTOELECTRONS

PUFFIN

QUOTAS

QUOTATION

RACETRACK

SCHROEDINGER

VEER

WATERWAY

YEARS

ZEST

Can anyone point me to a link of a script here that would do this type of thing? I've done searches but it must be because I don't know the AI terminology of what I'm trying to do. Thanks! :D

Share this post


Link to post
Share on other sites



Diana (Cda),

Assuming the word lists are standard text files, I would suggest using _FileListToArray to get the words into an array. Then use a loop with Random(1, $array[0], 1) to get however many random numbers you want and use them as indices to pull the words from the array. You might also need a bit of errorchecking to make sure you do not get the same word more than once.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi, in boredom I had a go at it.

Global $sWordsFile = @ScriptDir & "\Words.txt", $iNumberOfWords = 40

_RandomWordsToClipboard($sWordsFile, $iNumberOfWords)
If Not @error Then
    Run("notepad.exe")
    Sleep(100)
    WinActivate("[CLASS:Notepad]")
    Send(ClipGet())
EndIf

; #FUNCTION# ====================================================================================================================
; Name...........: _RandomWordsToClipboard
; Description ...: Copy a requested amount of random words from a word list to the clipboard
; Syntax.........: _RandomWordsToClipboard($sWordFile, $iNumberOfWords)
; Parameters ....: $sWordFile      - Path to a txt file that contains words (1 word per line)
;                  $iNumberOfWords - Number of words to send to the clipboard
; Return values .: Success - 1 and words are sent to the clipboard
;                  Failure - 0 and set @error
;                            @error -1 failed to open the $sWordsFile
;                            @error 1 ~ 2 failed creating an array from the $sWordsFile
;                            @error 3 $iNumberOfWords is greater then the amount of the words in $sWordsFile
; ===============================================================================================================================
Func _RandomWordsToClipboard($sWordFile, $iNumberOfWords)
    Local $hFO, $sFR, $aList, $iRandom, $sTmp, $iCP
    $hFO = FileOpen($sWordFile, 0)
    If $hFO = -1 Then Return SetError($hFO, 0, 0)
    $sFR = FileRead($hFO)
    FileClose($hFO)
    $aList = StringRegExp($sFR, "(?i)(.+)\n", 3)
    If @error Then Return SetError(@error, 0, 0)
    If $iNumberOfWords > UBound($aList) Then Return SetError(3, 0, 0)
    For $i = 1 To $iNumberOfWords
        $iRandom = Random(0, UBound($aList) - 1, 1)
        $sTmp &= $aList[$iRandom]
    Next
    $iCP = ClipPut(StringStripWS($sTmp, 2))
    Return SetError($iCP <> 1, 0, $iCP)
EndFunc   ;==>_RandomWordsToClipboard
Cheers Edited by smashly

Share this post


Link to post
Share on other sites

Wow, that's pretty impressive! <g> It's pretty neat to watch it in action.

I can add an inputbox and maybe browse-type of affair to the beginning so the user can specify which word list file to use, so most awesome! I can't thank you enough. I hope one day - perhaps even out of boredom, too - to put something together as easily <g>.

But I'm not recognizing something, the actual list of words, the number it will pull, is that random? I'm not familiar with very many aspects of AutoIt syntax yet though that's slowly, slowly growing but this part I'm guessing means that the script will generate of word list of a random number of words? Or do I have that wrong?:

For $i = 1 To $iNumberOfWords
        $iRandom = Random(0, UBound($aList) - 1, 1)
        $sTmp &= $aList[$iRandom]
Thanks! :D

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Wow, that's pretty impressive! <g> It's pretty neat to watch it in action.

I can add an inputbox and maybe browse-type of affair to the beginning so the user can specify which word list file to use, so most awesome! I can't thank you enough. I hope one day - perhaps even out of boredom, too - to put something together as easily <g>.

But I'm not recognizing something, the actual list of words, the number it will pull, is that random? I'm not familiar with very many aspects of AutoIt syntax yet though that's slowly, slowly growing but this part I'm guessing means that the script will generate of word list of a random number of words? Or do I have that wrong?:

For $i = 1 To $iNumberOfWords
        $iRandom = Random(0, UBound($aList) - 1, 1)
        $sTmp &= $aList[$iRandom]
Thanks! :D

Hi and your welcome, the number of words it pulls from the list is not a random amount...

You specify the number of words with the $iNumberOfWords parameter and the function will give you that many random selected words from the list.

What the function doesn't check for if the random word matches an already retrieved random word.

eg: you may end up with the same word twice or even more..

But it's not that hard to add a few more line of code to check that each word is different so you don't get duplicate words. I can add that check in if you like.

Cheers

PS.. How did you go with the m3u playlist thread you started the other day?

Another person and myself left you some pure autoit examples.

Edited by smashly

Share this post


Link to post
Share on other sites

Hi again, made it so you shouldn't get the same word more then once

_RandomWordsToClipboard(@ScriptDir & "\Words.txt", 50)
If Not @error Then
    Run("notepad.exe")
    Sleep(100)
    WinActivate("[CLASS:Notepad]")
    Send(ClipGet())
EndIf

; #FUNCTION# ====================================================================================================================
; Name...........: _RandomWordsToClipboard
; Description ...: Copy a requested amount of random words from a word list to the clipboard
; Syntax.........: _RandomWordsToClipboard($sWordFile, $iNumberOfWords)
; Parameters ....: $sWordFile      - Path to a txt file that contains words (1 word per line)
;                  $iNumberOfWords - Number of words to send to the clipboard
; Return values .: Success - 1 and words are sent to the clipboard
;                  Failure - 0 and set @error
;                            @error -1 failed to open the $sWordsFile
;                            @error 1 ~ 2 failed creating an array from the $sWordsFile
;                            @error 3 $iNumberOfWords is greater then the amount of the words in $sWordsFile
; ===============================================================================================================================
Func _RandomWordsToClipboard($sWordFile, $iNumberOfWords)
    Local $hFO, $sFR, $aList, $iRandom, $sTmp, $iCP
    $hFO = FileOpen($sWordFile, 0)
    If $hFO = -1 Then Return SetError($hFO, 0, 0)
    $sFR = FileRead($hFO)
    FileClose($hFO)
    $aList = StringRegExp($sFR, "(?i)(.+)\n", 3)
    If @error Then Return SetError(@error, 0, 0)
    If $iNumberOfWords > UBound($aList) Then Return SetError(3, 0, 0)
    For $i = 1 To $iNumberOfWords
        Do
            $iRandom = Random(0, UBound($aList) - 1, 1)
        Until (Not StringInStr($sTmp, $aList[$iRandom]))
        $sTmp &= $aList[$iRandom]
    Next
    $iCP = ClipPut(StringStripWS($sTmp, 2))
    Return SetError($iCP <> 1, 0, $iCP)
EndFunc   ;==>_RandomWordsToClipboard

Cheers

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0