加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vb.net – 生成随机数到2位小数

发布时间:2020-12-17 07:21:36 所属栏目:百科 来源:网络整理
导读:blah = CInt(Int((7 * Rnd()) + 0)) 生成0到6之间的随机整数. 如何修改它给我一个带有2位小数的随机数,仍然在0到6之间? 如下所示,我现在使用此代码,它似乎工作: Dim prng As New RandomPrivate Function aRand() As Double Return Math.Round(prng.Next(0,
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()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读