|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 zopey 于 2018-10-2 08:56 编辑
Private Sub CommandButton1_Click()
Cells.ClearContents
Dim m&, n&, r&, s&, z&
m = 100 '取数范围m
n = 50 '每组个数n
s = 25 '相同个数s
z = 3 '组数z
For i = 1 To m
Cells(i, 1) = Rnd()
Cells(i, 2) = i
Next
Columns("A:B").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess
Dim arr, brr(), r1, r2, r3
arr = [b1].Resize(m, 1)
ReDim brr(1 To m, 1 To z)
r1 = Int(Rnd() * (s + 1))
r2 = s - r1
r3 = n - s - r2
For i = 1 To r1
For j = 1 To z
brr(i, j) = arr(i, 1)
Next
Next
For i = 1 To r2 * z
k = Int((i - 1) / r2)
If k = 0 Then
brr(r1 + i, 1) = arr(r1 + i, 1)
brr(r1 + i, 2) = arr(r1 + i, 1)
ElseIf k = 1 Then
brr(r1 + i, 2) = arr(r1 + i, 1)
brr(r1 + i, 3) = arr(r1 + i, 1)
ElseIf k = 2 Then
brr(r1 + i, 3) = arr(r1 + i, 1)
brr(r1 + i, 1) = arr(r1 + i, 1)
End If
Next
For i = 1 To r3 * z
k = Int((i - 1) / r3)
brr(r1 + r2 * z + i, k+1) = arr(r1 + r2 * z + i, 1)
Next
[d1].Resize(m, z) = brr
End Sub
z=3(3个集合) 比较简单,拿来练练手
3集合交集.rar
(12.17 KB, 下载次数: 2)
|
|