求数字乱序排列的编程思路
求数字乱序排列的编程思路已知条件:
dim a as string
a="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21"
如何将这21个数字随机取出(取出来还是21个)? 不要代码,求思路。
[此贴子已经被作者于2020-11-24 21:04编辑过]
[此贴子已经被作者于2020-11-24 21:04编辑过]
Sub Shuffle(ByRef a) Dim t, j, n n = UBound(a) Randomize For i = n To 1 Step - 1 j = Int(Rnd * (i + 1)) t = a(j) a(j) = a(i) a(i) = t Next End Sub Dim Array(20) '数组0到20,共21个数字 Dim str str = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21" '要随机的数字这样赋值 S = Split(str,",") '以逗号作为分割 For i = 0 To UBound(S) Array(i) = S(i) Next a = Array(20) '数组的个数。0到20,共21个 WScript.Echo Join(Array) '洗牌前 Shuffle Array WScript.Echo Join(Array) '洗牌后 word = Join(Array) T=split(word," ") '以空格作为分隔符 For j = 0 To ubound(T) MsgBox T(j) Next
[此贴子已经被作者于2020-12-14 09:53编辑过]