标签:
算法图示:
运行效果:
详细代码:
Option Explicit ‘洗16张牌(0-15),方便用十六进制显示 Private Const CARDMAX = 15 Dim Card() As Long Private Sub 洗牌() Dim i&, l&, r&, t& l = CARDMAX For i = 0 To CARDMAX r = Rnd * l t = Card(l) Card(l) = Card(r) Card(r) = t l = l - 1 Next i End Sub Private Sub Command1_Click() Call 洗牌 ‘输出洗牌结果和牌点总和 Dim i As Long Dim n As Long For i = 0 To CARDMAX Print Hex(Card(i)); n = n + Card(i) Next i Print " - SUM:" & n End Sub Private Sub Form_Load() Randomize ‘初始化牌 ReDim Card(CARDMAX) Dim i As Long For i = 0 To CARDMAX Card(i) = i Next i End Sub
标签:
原文地址:http://www.cnblogs.com/youyouran/p/5361956.html