20/01/2013

How to Generate Random Number? VB.Net Code

Random Numbers have its own importance in any type of computer programming. It play very important role in video game development or animation creation or for doing some software development for lottery result etc. Therefore in VB.Net also we can generate a random number very easily and can utilize as per our requirement. Place following control on your Windows form
  • List box- to display the random number
  • Command Button to execute the command
And write down following VB.Net code on the click even of Command Button

Private Sub BtnRndGenerator_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRndGenerator.Click
        Dim Generator As New Random
        Dim myrandm As Integer
        ListBox1.Items.Clear()
        Do
            myrandm = Generator.Next(0, 25)
            ListBox1.Items.Add(myrandm.ToString())

        Loop While myrandm <> 5

For more clarification please see this video.