## 随机不重复数组的提问

Moderators: arcticir, tmplinshi

lychee219
Posts: 1
Joined: 03 Jun 2020, 21:38

### 随机不重复数组的提问

Code: Select all

``````F3::
{
A := []
lencount=0
While(lencount<15)
{
res := % rnd(1,23)
If %res% not In %A%
{
A[A_Index]:= %res%
lencount++
}
}
str := ""
Loop,% A.Length()
{
str .= A[A_Index] . ","
}
MsgBox,% str

rnd(mn,mx)
{
Random, num, %mn%,%mx%
return num
}
}``````

Yakshongas
Posts: 587
Joined: 21 Jan 2020, 08:41

### Re: 随机不重复数组的提问

Code: Select all

``````F3::
Numbers :="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23"
Sort, Numbers, Random D,
NumbersArray := StrSplit(Numbers, ",")

Loop, 16
{
MsgBox, % NumbersArray[A_Index]
}
Return``````
Please mark your topics as solved if you don't need any further help.

Need a little more help? Discord : Yakshongas#9893 🕹

garry
Posts: 2412
Joined: 22 Dec 2013, 12:50

### Re: 随机不重复数组的提问

@Yakshongas thank you

Code: Select all

``````;-------- saved at 星期六 六月 2020-06-06  17:56 UTC --------------
;- 随机不重复数组的提问  / user=lychee219 / solution = Yakshongas
;- https://www.autohotkey.com/boards/viewtopic.php?f=27&t=76862
;- Numbers :="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23"

#warn
#Singleinstance,force
numbers:=""
e:=""

\$F3::
loop,23
numbers .= a_index . ","
;msgbox,%numbers%
Sort, Numbers, Random D,
NumbersArray := StrSplit(Numbers, ",")
i=0
Loop,16
{
i++
aa:=NumbersArray[A_Index]
e .= aa . ","
;msgbox, 262208,RANDOM-LOOP (16)  I=%i%,%aa%,2  ;- show for 2 seconds
}
sort,e,N D,
msgbox, 262208,LOOP-END,%e%
e=
aa=
numbersarray=
numbers=
return
esc::exitapp

``````

Yakshongas
Posts: 587
Joined: 21 Jan 2020, 08:41

### Re: 随机不重复数组的提问

You're welcome @garry
Please mark your topics as solved if you don't need any further help.

Need a little more help? Discord : Yakshongas#9893 🕹

feiyue
Posts: 230
Joined: 08 Aug 2014, 04:08

### Re: 随机不重复数组的提问

Code: Select all

``````
min:=1, max:=230000, num:=160000

F3::
SetBatchLines, % (-1, bch:=A_BatchLines)

t:=A_TickCount
s:="", i:=min
loop, % max-min+1
s.=(i++) ","
s:=SubStr(s, 1, -1)
Sort, s, Random D,
a:=StrSplit(s, ",")
msgbox, % A_TickCount-t

t:=A_TickCount
a:=[], i:=min
loop, % all:=max-min+1
a[A_Index]:=i++
Loop, % num
{
Random, k, (i:=A_Index), all
v:=a[k], a[k]:=a[i], a[i]:=v
}
msgbox, % A_TickCount-t

SetBatchLines, %bch%
return

``````