spel565 Posted August 20, 2009 Share Posted August 20, 2009 Can i make a script that picks one of f.ex 5words (i have choosen) randomly Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 20, 2009 Moderators Share Posted August 20, 2009 spel565, If I understand yor question correctly, place the words into an array and then use a random index number: Global $asWords[4] = [3, "Tom", "Dick", "Harry"] While 1 $iIndex = Random(1, 3, 1) ; random integer 1, 2 or 3 MsgBox(0, "Result", $asWords[$iIndex]) WEnd 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 Link to comment Share on other sites More sharing options...
spel565 Posted August 20, 2009 Author Share Posted August 20, 2009 spel565, If I understand yor question correctly, place the words into an array and then use a random index number: Global $asWords[4] = [3, "Tom", "Dick", "Harry"] While 1 $iIndex = Random(1, 3, 1) ; random integer 1, 2 or 3 MsgBox(0, "Result", $asWords[$iIndex]) WEnd M23 Thanks now everything works >_< Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 20, 2009 Moderators Share Posted August 20, 2009 spel565,First, please do not send PMs asking for help - it is considered rude. If you post your questions in the forums, then everyone can learn - which is why we are here! >_< OK, you want word 1 more often than word 2, and word 2 more often than word 3, etc.Two ways to do this:1. As you suggested, add more elements to the array - but you need to increase the size of the array - look carefully at the difference between your code and mine:; Your code Global $asWords[4] = [3, "1", "1", "1", "2", "3", "3", "2", "5"] $iIndex = Random(1, 8, 1) MsgBox(0, "Result", $asWords[$iIndex]) ; My code Global $asWords[9] = [3, "1", "1", "1", "2", "3", "3", "2", "5"] $iIndex = Random(1, 8, 1) MsgBox(0, "Result", $asWords[$iIndex])Spotted the difference? if not, look carefully at the Global $asWords[#] part!But you could also use another method which uses fewer resources:Global $asWords[4] = [3, "Tom", "Dick", "Harry"] While 1 $nRandom = Random() ;produce a random number between 0 and 1 Switch $nRandom Case 0 To .5 ; this will be true 50% of the time $iIndex = 1 Case .5 To .85 ; this will be true 35% of the time $iIndex = 2 Case Else ; this will be true only 15% of the time $iIndex = 3 EndSwitch MsgBox(0, "Result", $asWords[$iIndex]) WEndTo change the ratios, just alter the numbers in the Case statements. Your array remains at the smaller size, so fewer resources used.Ask if anythng is unclear.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 Link to comment Share on other sites More sharing options...
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