需要创建10到20之间的随机数

时间:2016-02-18 22:56:20

标签: vb.net random numbers generator

我正在尝试为我的程序生成10到20之间的随机数,但生成的数字小于1,并且是2位小数,例如0.64,0.34等。

Dim TrigB As Random
    Dim numberb As Integer
    TrigB = New Random
    numberb = TrigB.Next(10, 20)
    TrigRdmb.Text = numberb.ToString

我需要更改什么才能产生10到20之间的数字

感谢

1 个答案:

答案 0 :(得分:0)

除了TrigB.Next(10, 20)您应该将其TrigB.Next(10, 21)写为20以使其包含Random.Next之外,您的代码就可以了。对于Return Integer Random.NextDouble

如果您的价值低于1,那么您可能会拨打Random.Next而不是//fromDate is start date and toDate is end Date var timeDiff = Math.abs(toDate.getTime() - fromDate.getTime()); var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)) ; // var startDay = fromDate.getDay(); debugger; var diffDayWeek = diffDays + fromDate.getDay(); var diffDiv = Math.floor(parseInt(diffDayWeek/7)); diffDiv *= 2; "Saturday and Sunday are Weekend diffDays += 1 - diffDiv;