生成随机数到2位小数

fin*_*rre 5 vb.net

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)

感谢所有的建议.

dba*_*ett 3

像这样

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)

  • 您的答案将不包括 6.00 在其范围内。 (2认同)