## How to traverse 1-9 random numbers quickly and randomly? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
afe
Posts: 618
Joined: 06 Dec 2018, 04:36

### How to traverse 1-9 random numbers quickly and randomly?

How to traverse 1-9 random numbers quickly and randomly?
Does this algorithm need to be improved?

Code: Select all

``````a := []
loop, 9
{
Loop
{
b := 0
i := random()

for key, value in a
{
If value = i
{
b := 1
break
}
}

if ( b = 0 )
{
a.push(i)
break
}
}

}
return

random()
{
Random, r, 1, 9
return, r
}
``````
Helgef
Posts: 4464
Joined: 17 Jul 2016, 01:02
Contact:

### Re: How to traverse 1-9 random numbers quickly and randomly?  Topic is solved

if Value = i should be if (Value = i), or if value = %i%, although that isn't recommended.

Another way,

Code: Select all

``````unique_array(n){
local str := ""
loop % n
str .= a_index .  "`n"
str := rtrim(str, "`n")
sort str, random
return strsplit(str,  "`n")
}
; Edit, removed unused function
``````
Cheers.
Last edited by Helgef on 17 May 2020, 01:17, edited 1 time in total.
afe
Posts: 618
Joined: 06 Dec 2018, 04:36

Thanks, great!

### Who is online

Users browsing this forum: anv, Bing [Bot], DaveT1, JoeWinograd, LakaiHigh, mikeyww, TheProdigyC2, TXShooter and 77 guests