标签:style blog color io 使用 for sp div on
‘程序的思路是将a,b分别给一个0到num-1的随机数,循环多次,观察(a,b)的所有组合出现的次数,用来反映其出现的概率
‘测试结果表明连续使用Randomize,出现的(a,b)组合并不是等概率的
Option Explicit Sub Cal(ByVal num As Integer) Dim a, b, i, j, k, n, c() As Long ReDim c(num * num - 1) For i = 1 To 500000 Randomize a = Int(Rnd * num) Randomize ‘此处注释后结果不同 b = Int(Rnd * num) n = 0 For j = 0 To num - 1 If a = j Then For k = 0 To num - 1 If b = k Then GoTo f End If n = n + 1 Next k End If n = n + num Next j f: c(n) = c(n) + 1 Next i For i = 0 To num * num - 1 Debug.Print c(i), Next i Debug.Print End Sub Private Sub Command1_Click() Call Cal(3) End Sub
VB6中连续使用Randomize对后续随机数出现概率影响测试
标签:style blog color io 使用 for sp div on
原文地址:http://www.cnblogs.com/Blessing/p/3994972.html