Dxnny Posted May 1, 2021 Share Posted May 1, 2021 Hi, I want my script to run something different 9 times out of 10 times, but on the rare occasion that it lands on 1 I want it to sleep. What I've wrote isn't working, it always shows "Failed: Message not sent", it never shows "Success: Message sent" Basically what I'm after is for it to get a number between 1 and 10, and if that number is 1, then sleep, if its anything other than 1 do something else. #include <Misc.au3> HotKeySet("{F1}","stopScript") While 1 sleep(Random(1000, 3000)) If Random(1, 10, 1) Then sleep(Random(1000, 3000)) ConsoleWrite("Failed: Message not sent" & @CRLF) Else ConsoleWrite("Success: Message sent" & @CRLF) EndIf WEnd Func stopScript () msgbox (0, "Stopping script", "Script has been stopped.") Exit EndFunc Link to comment Share on other sites More sharing options...
TheXman Posted May 1, 2021 Share Posted May 1, 2021 (edited) 36 minutes ago, Dxnny said: Basically what I'm after is for it to get a number between 1 and 10, and if that number is 1, then sleep, if its anything other than 1 do something else How is this topic different from the one below? If it isn't, then why did you create a new topic? Edited May 1, 2021 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Nine Posted May 1, 2021 Share Posted May 1, 2021 42 minutes ago, Dxnny said: If Random(1, 10, 1) Then This will always return true since you ask for a random number between 1 and 10. Only the number 0 is consider False. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Dxnny Posted May 1, 2021 Author Share Posted May 1, 2021 8 minutes ago, Nine said: This will always return true since you ask for a random number between 1 and 10. Only the number 0 is consider False. How do I make it all the other numbers except for 1 then? Link to comment Share on other sites More sharing options...
Nine Posted May 1, 2021 Share Posted May 1, 2021 If random(1,10,1) = 1 then ;do something else ; do somethig else endif “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
JockoDundee Posted May 1, 2021 Share Posted May 1, 2021 If Random(0,9,1) Then Exit Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
JockoDundee Posted May 1, 2021 Share Posted May 1, 2021 déjà vu Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Musashi Posted May 1, 2021 Share Posted May 1, 2021 Just for fun, another variation : #include <Misc.au3> HotKeySet("{F1}", "stopScript") Local $bSuccess, $iRandom While 1 Sleep(Random(1000, 3000)) $iRandom = Random(1, 10, 1) $bSuccess = ($iRandom = 1) ? True : False If Not $bSuccess Then Sleep(Random(1000, 3000)) ConsoleWrite("!Random Value = " & StringFormat("%2i", $iRandom) & " ==> Failed: Message not sent" & @CRLF) Else ConsoleWrite("+Random Value = " & StringFormat("%2i", $iRandom) & " ==> Success: Message sent" & @CRLF) EndIf WEnd Func stopScript() MsgBox(0, "Stopping script", "Script has been stopped.") Exit EndFunc ;==>stopScript "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." 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