关于随机乱序洗牌是如何实现的呢?- Public Sub xp() ' 洗牌
- Dim i%, j%, k%, l!, r%, t(1 To 1, 1 To 5)
- k = 0
- zp1 = 说明.Range("a1:d14").Value
- ReDim zp2(1 To 54, 1 To 5)
- For j = 1 To 4
- l = 0
- For i = 2 To 14
- k = k + 1
- zp2(k, 1) = k '序号
- zp2(k, 2) = zp1(i, j) '牌面
- zp2(k, 3) = i + 2 '行号
- zp2(k, 4) = j + 11 '列号
- If i < 12 Then l = l + 1 Else l = 0.5
- zp2(k, 5) = l '点数
- Next i
- Next j
- zp2(53, 1) = 53: zp2(53, 2) = "王1": zp2(53, 3) = 3: zp2(53, 4) = 13: zp2(53, 5) = 0.5
- zp2(54, 1) = 54: zp2(54, 2) = "王2": zp2(54, 3) = 3: zp2(54, 4) = 14: zp2(54, 5) = 0.5
- Randomize
- For i = 1 To 54 '香川【经典数组洗牌法】之多维应用
- r = Int(Rnd() * (54 - i + 1)) + i
- For j = 1 To 5
- t(1, j) = zp2(r, j): zp2(r, j) = zp2(i, j): zp2(i, j) = t(1, j)
- Next j
- Next i
- ancx = 1
- MsgBox "随机乱序洗牌完毕,可以发牌!", , "友情提示"
- End Sub
复制代码 对,来自于尊敬的香川大侠!!! |