uvlights Posted May 15, 2023 Share Posted May 15, 2023 (edited) Hi, I'm writing on a dart scorer programm. I'm stuck with implementing a random generator to choose a random start player. I listed the members in an ini file like this: [m1] name = "Testname1" [m2] name = "Testname" and so on... I want to generate as many random numbers, as I have players in the ini. But I don't want any duplicates of course and that's where I'm stuck. here's the code: Global $randomnumber[11] $ini_sections = IniReadSectionNames(@ScriptDir & "\members.dat") For $i = 1 To UBound($ini_sections) - 1 Do $randomnumber[$i] = Random(1, UBound($ini_sections) - 1, 1) Until $randomnumber[$i] = $randomnumber[$i - 1] = False Next _ArrayDisplay($randomnumber) like this I can ensure that number no.2 doesn't equal number 1. But then I'm stuck idk how to move on. Edited May 15, 2023 by uvlights Link to comment Share on other sites More sharing options...
TheXman Posted May 15, 2023 Share Posted May 15, 2023 17 minutes ago, uvlights said: I'm stuck idk how to move on. Let me guess, you searched the forum for something like "unique random numbers" and couldn't find anything? 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...
Solution Danp2 Posted May 15, 2023 Solution Share Posted May 15, 2023 Here's a simple example using _ArrayShuffle -- #include <array.au3> Global $iCount = 3 Global $randomnumber[$iCount] For $i = 0 To $iCount - 1 $randomnumber[$i] = $i + 1 Next _ArrayDisplay($randomnumber, 'pre-shuffle') _ArrayShuffle($randomnumber) _ArrayDisplay($randomnumber, 'post-shuffle') uvlights 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
uvlights Posted May 15, 2023 Author Share Posted May 15, 2023 45 minutes ago, Danp2 said: Here's a simple example using _ArrayShuffle -- #include <array.au3> Global $iCount = 3 Global $randomnumber[$iCount] For $i = 0 To $iCount - 1 $randomnumber[$i] = $i + 1 Next _ArrayDisplay($randomnumber, 'pre-shuffle') _ArrayShuffle($randomnumber) _ArrayDisplay($randomnumber, 'post-shuffle') Thank you Danp2! Have a blessed day! Link to comment Share on other sites More sharing options...
uvlights Posted May 15, 2023 Author Share Posted May 15, 2023 49 minutes ago, TheXman said: Let me guess, you searched the forum for something like "unique random numbers" and couldn't find anything? why are u even in this forum? I'm a beginner. I couldn't find anything. Link to comment Share on other sites More sharing options...
TheXman Posted May 15, 2023 Share Posted May 15, 2023 My question was obviously rhetorical. I was trying to help you learn how to help yourself. If you did the search that I suggested and still didn't find anything, then you are a MORON! 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...
uvlights Posted May 15, 2023 Author Share Posted May 15, 2023 6 minutes ago, TheXman said: My question was obviously rhetorical. I was trying to help you learn how to help yourself. If you did the search that I suggested and still didn't find anything, then you are a MORON! nobody needs people like you in a forum. if you're not willing to answer, or if you just had a bad day, please don't reply at all the next time. thanks. Nine 1 Link to comment Share on other sites More sharing options...
Developers Jos Posted May 15, 2023 Developers Share Posted May 15, 2023 (edited) @uvlights, I do understand the emotions one gets when when being told that you could have searched and find the answer yourself, but don't you agree there's also some truth in that statement and did you really try to search ? (No need to answer this here, but rather only to yourself. The real answer is shown when you click the link) Here's my advice to you: don't start the "you don't belong here" battle in public unless you know who you are dealing with, and simply ignore comments when you don't like them. 😉 PS: There is no need to make 2 reports on posts you don't like.... one will suffice and welcome to the Internet in case these posts are bothering you. Edited May 15, 2023 by Jos ioa747 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts