blah = CInt(Int((7 * Rnd()) + 0))
Run Code Online (Sandbox Code Playgroud)
生成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()
Run Code Online (Sandbox Code Playgroud)
感谢所有的建议.
像这样
Dim prng As New Random
Private Function aRand() As Double
Return prng.Next(0, 601) / 100
End Function
Run Code Online (Sandbox Code Playgroud)
注意位置随机。
你的代码看起来像
currentApp.statements(Pick, 7) = aRand()
currentApp.statements(Pick, 8) = aRand()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6808 次 |
| 最近记录: |