blah = CInt(Int((7 * Rnd()) + 0)) 生成0到6之间的随机整数. 如何修改它给我一个带有2位小数的随机数,仍然在0到6之间? 如下所示,我现在使用此代码,它似乎工作: Dim prng As New RandomPrivate Funct
blah = CInt(Int((7 * Rnd()) + 0))
生成0到6之间的随机整数.
如何修改它给我一个带有2位小数的随机数,仍然在0到6之间?
如下所示,我现在使用此代码,它似乎工作:
Dim prng As New Random Private Function aRand() As Double Return Math.Round(prng.Next(0, 601) / 100, 2) End Function currentApp.statements(Pick, 7) = aRand() currentApp.statements(Pick, 8) = aRand()
感谢所有的建议.
像这样Dim prng As New Random Private Function aRand() As Double Return prng.Next(0, 601) / 100 End Function
注意随机的位置.
你的代码看起来像
currentApp.statements(Pick, 7) = aRand() currentApp.statements(Pick, 8) = aRand()