Jump to content

Random Number Generator with multiple numbers HELP PLEASE


Go to solution Solved by Danp2,

Recommended Posts

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 by uvlights
Link to comment
Share on other sites

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? 

Link to comment
Share on other sites

  • Solution

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')

 

Link to comment
Share on other sites

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

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

 

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Developers

@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 by Jos

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

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...