Diana (Cda) Posted September 5, 2009 Posted September 5, 2009 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!
Moderators Melba23 Posted September 5, 2009 Moderators Posted September 5, 2009 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
smashly Posted September 6, 2009 Posted September 6, 2009 (edited) Hi, in boredom I had a go at it. expandcollapse popupGlobal $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 ;==>_RandomWordsToClipboardCheers Edited September 9, 2009 by smashly
Diana (Cda) Posted September 6, 2009 Author Posted September 6, 2009 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!
smashly Posted September 6, 2009 Posted September 6, 2009 (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! 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 September 6, 2009 by smashly
smashly Posted September 6, 2009 Posted September 6, 2009 Hi again, made it so you shouldn't get the same word more then onceexpandcollapse popup_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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now