在区间VB.NET中使用循环生成随机数

时间:2016-05-15 14:01:38

标签: vb.net loops random integer intervals

如何在标题栏中的0-99之间的间隔中生成随机数循环,如下所示:https://www.dropbox.com/s/n6cvxlpjzklys80/vb.gif

我能够在菜单栏中生成随机数,但无法在特定时间间隔内循环它们。

Dim value As Integer = CInt(Int((99 * Rnd()) + 1))
Dim randomnumber As String = "My random no. between " & value.ToString

Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Me.Text = randomnumber

    End Sub

1 个答案:

答案 0 :(得分:0)

为您的项目和此代码添加Windows窗体计时器

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.Timer1.Interval = 100 '10 per second
    Me.Timer1.Start()
End Sub

Private Shared prng As New Random
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Me.Text = "My random no. between " & prng.Next(100)
End Sub