mucitbey Posted November 2, 2020 Share Posted November 2, 2020 Hello friends. How can I prevent the same number from being repetitive in this program. Thank you in advance for your help. expandcollapse popup#include <Array.au3> #include <GuiConstants.au3> Dim $Num[6] Global $_Chck = False Global $Gui = GUICreate("", 610, 170, -1,-1, $WS_POPUP+$WS_BORDER) GUISetBkColor(0x3366FF) Local $Genr = GUICtrlCreateButton("Generate Number", 10, 10, 300, 35) GUICtrlSetFont(-1, 20, 800, 0, "Arial Narrow") Local $Exit = GUICtrlCreateButton("CLOSE", 500, 10, 100, 35) GUICtrlSetFont(-1, 20, 800, 0, "Arial Narrow") Global $I[6] For $N = 0 To 5 $I[$N] = GUICtrlCreateInput("", 10 + 100 * ($N), 60, 90, 100, $ES_READONLY+$ES_CENTER) GUICtrlSetFont(-1, 70, 800, 0, "Arial Narrow") Next GUISetState() While 1 $Msg = GUIGetMsg() Select Case $Msg = -3 Or $Msg = $Exit Exit Case $Msg = $Genr If $_Chck = False Then $_Chck = True Else $_Chck = False EndIf If $_Chck = True Then GUICtrlSetData($Genr, 'STOP') AdlibRegister('_RandomNum', 10) EndIf If $_Chck = False Then GUICtrlSetData($Genr, 'Generate Number') _ArraySort($Num) For $N = 0 To 5 GUICtrlSetData($I[$N], $Num[$N]) Next AdlibUnRegister('_RandomNum') EndIf EndSelect WEnd Func _RandomNum() For $N = 0 To 5 $Num[$N] = Random(1, 90, 1) GUICtrlSetData($I[$N], $Num[$N]) Next EndFunc Link to comment Share on other sites More sharing options...
TheDcoder Posted November 2, 2020 Share Posted November 2, 2020 Use an array to store the currently generated numbers and check against it to make sure there are no duplicates. mucitbey 1 EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Nine Posted November 2, 2020 Share Posted November 2, 2020 Here a simple way : Func _RandomNum() For $N = 0 To 5 $Num[$N] = Random(1, 90, 1) For $C = 0 To 5 If $C = $N Then ContinueLoop If $Num[$C] = $Num[$N] Then $N -= 1 ;ConsoleWrite ("Found duplicate" & @CRLF) ContinueLoop 2 EndIf Next GUICtrlSetData($I[$N], $Num[$N]) Next EndFunc ;==>_RandomNum mucitbey 1 “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...
TheXman Posted November 2, 2020 Share Posted November 2, 2020 (edited) Another simple way: #include <Array.au3> _ArrayDisplay(lotto_numbers(), "Lotto Numbers") Func lotto_numbers() Local $aAvailableNumbers[0], $aSelectedNumbers[0] Local $iRandomIndex ;Load available numbers For $i = 1 To 90 _ArrayAdd($aAvailableNumbers, $i) Next ;Select 6 random, non-repeating, numbers from available numbers For $i = 1 To 6 $iRandomIndex = Random(0, UBound($aAvailableNumbers) - 1, 1) ;Random available number index _ArrayAdd($aSelectedNumbers, $aAvailableNumbers[$iRandomIndex]) ;Add available number to selected numbers _ArrayDelete($aAvailableNumbers, $iRandomIndex) ;Remove selected number from available numbers Next Return $aSelectedNumbers EndFunc Edited November 2, 2020 by TheXman mucitbey 1 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...
mucitbey Posted November 2, 2020 Author Share Posted November 2, 2020 You're great #Nine, we thank you once again. Also thanks #TheXman for a different recommendation. Link to comment Share on other sites More sharing options...
jchd Posted November 2, 2020 Share Posted November 2, 2020 Another skin for this cat: Local $N = 99 Local $a[$N] For $i = 0 To $N - 1 $a[$i] = $i + 1 Next For $i = 1 To 8 _ArrayShuffle($a) ; display 6 random numbers without dups ConsoleWrite(_ArrayToString($a, " ", 0, 5, " ") & @LF) Sleep(1000) Next Exit 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) 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