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](https://www.sourcecodester.com/sites/default/files/design_3.png)
Next, in the code tab, create a code for your Button1_Click. Type this code below:
Public Class Form1
Public random As New Random()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
For i = 1 To 3
MsgBox(Convert
.ToString(random
.Next(0,
1000))) Next
End Sub
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](https://www.sourcecodester.com/sites/default/files/final_output_1.png)
Click
OK button in the MessageBox again. It will generate again a random number like this:
![2](https://www.sourcecodester.com/sites/default/files/1_0.png)
Lastly, click the
OK button. It will generate again a random number like this:
![three](https://www.sourcecodester.com/sites/default/files/2_0.png)
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