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: 616
Joined: 06 Dec 2018, 04:36

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

16 May 2020, 11:11

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: 4467
Joined: 17 Jul 2016, 01:02
Contact:

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

16 May 2020, 11:46

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.

Return to “Ask For Help”

Who is online

Users browsing this forum: Delta Pythagorean, Noesis, pyn, TheNomadicAspie and 30 guests