frew Posted May 27, 2009 Posted May 27, 2009 Hello, I've got a set of numbers 1 through 20. From that set, I want a certain subset (ie 1 through 5) to printed in a random order. I do not want any duplicate numbers in the result, for example not 2, 4, 5, 2, 1 Is there any addition to this kind of little script that will get that result? The kinds of results I want are like this: 1, 4, 2, 3, 5 2, 5, 3, 1 ,4 4, 2, 3, 5, 1 Preferably, I do not want to have to use an array at this time. How can I prevent repetitions of a number from showing up in the resulting five numbers? Local $w = 0 While $w < 5 Sleep(10) $i = Random(1, 20, 1) Switch $i Case $i = 1, 2, 3, 4, 5 MsgBox(0, '', $i, 1) Case Else ContinueLoop EndSwitch $w = $w + 1 WEnd Thanks for any ideas for me to try. frew
DaleHohm Posted May 27, 2009 Posted May 27, 2009 The solution using an array is very simple. Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble
frew Posted May 27, 2009 Author Posted May 27, 2009 The solution using an array is very simple. Could 1 through 20 be put into an array, and then give me the results of 1 through 5, where 1 through 5 are displayed in random order, and without a 1, 2, 3, 4, or 5 showing up two or more times in the results? Any ideas on how to do that? Thank you, frew
Malkey Posted May 27, 2009 Posted May 27, 2009 This way works. ; Local $w = 0, $i, $j = "" While $w < 5 Sleep(10) $i = Random(1, 20, 1) Switch $i Case 1, 2, 3, 4, 5 If StringInStr($j, $i) = 0 Then $j &= $i & ", " $w += 1 EndIf Case Else ContinueLoop EndSwitch WEnd MsgBox(0, '', StringTrimRight($j, 2)) ;
frew Posted May 27, 2009 Author Posted May 27, 2009 This way works.Malkey, Thanks so much!Yes, that works great.Sorry I couldn't get back to you sooner. I was trying to see how your code works.I'm not familiar with StringInStr so I'm still checking it out.Thanks again so much for the help with this. I'm learning from your code example which provides theexact results I was hoping for.I hadn't thought to try StringInStr with numbers.frew
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