Random Number Generator using VB.NET

Hi! this is my another tutorial for VB.NET entitled "Random Number Generator". Some of the systems and applications today are using a Random Number Generator to generate random id number which will be used for their id in the database or let's just say an application by guessing a number. So, now let's start making this program! Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New, and choose Windows Form Application. Next, add one button and named Button1. Have it also labeled as "Create Random Number". Follow this designed layout: design Next, in the code tab, create a code for your Button1_Click. Type this code below:
  1. Public Class Form1
  2. Public random As New Random()
  3. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4. Dim i As Integer
  5. For i = 1 To 3
  6. MsgBox(Convert.ToString(random.Next(0, 1000)))
  7. Next
  8. End Sub
  9. End Class
We declare Public random As New Random() as our Global Variable for instantiating a Random Object (New Random()) that holds the variable random. We also initializes  Dim i As Integer as our integer so that we can generate three random numbers (For i=1 to 3) when we click OK button in the MsgBox. MsgBox(Convert.ToString(random.Next(0, 1000))) syntax is for displaying the random number.  random.Next(0, 1000) initializes a random number from 0 to 1000, then the output is converted into a string using Convert.ToString syntax. Now, click your Button. It will now generate random number like this: one Click OK button in the MessageBox again. It will generate again a random number like this: 2 Lastly, click the OK button. It will generate again a random number like this: three We can only generate random number three times as we conditioned For i = 1 to 3. Download the source code below and try it! :) For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]

Visit and like my page on Facebook at: Bermz ISware Solutions

Subscribe at my YouTube Channel at: SerBermz

Add new comment