开发者

Getting a random number in MS Visual Basic 2008

I am new to MS Visual Basic 2008. In fact, I am currently enrolled in the class. My final project for the class will gene开发者_高级运维rate random numbers within a range of numbers. For example, if I give the user five text windows to choose whether to input a number OR generate a random number, I will have a button called RANDOMIZE. Unfortunately, I do not know the line(s) of code for the random function.

Thank you for the assistance.


Try this method to generate a random number with a given min and max range:

Private Function GenerateRandomNumber(min As Integer, max As Integer) As Integer
   Dim random As New Random()
   Return random.Next(min, max)
End Function 

Call it like this:

 Dim i As Integer = GenerateRandomNumber(0,Int32.MaxValue);


You should check out the documentation for Randomize() Here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜