如何使用EXCEL表在5*5的矩阵中随机生成1-25之间的随机数 不重复

2024-11-22 12:24:07
推荐回答(3个)
回答(1):

复制如下代码到VBA中,运行即可

Public Sub gen()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim a(25) As Integer

a(0) = Int(Rnd() * 25) + 1

For i = 1 To 24
LL:
k = Int(Rnd() * 25) + 1
For j = 1 To i - 1
If a(j) = k Then GoTo LL
Next j
a(i) = k
Next i

For i = 1 To 5
For j = 1 To 5
Cells(i, j) = a((i - 1) * 5 + (j - 1))
Next j
Next i
End Sub

回答(2):

选择一个5×5的区域,如A1:E5,在输入栏输入
=RANDBETWEEN(1,25)
按CTRL+回车结束公式输入
但要得到不重复的数据,且随机,可能要费点事了

回答(3):

不重复的话,只有用vba去生成了