abhi wrote:
How do you get random numbers in vb .net?
I want random six digit numbers.
Cheers,
Abhi
Does anyone even try using a search engine anymore? The second item
aftger a "vb.net random number" search is:
http://authors.aspalliance.com/brett...rsInVB.NET.asp
Random Integers
Once the class has been instantiated, a random integer can be obtained
by calling the Next method of the Random class:
http://authors.aspalliance.com/brett...rsInVB.NET.asp
Random numbers may be generated in the .NET Framework by making use of
the Random class. This class may be instantiated using the following code:
'Create a new Random class in VB.NET
Dim RandomClass As New Random()
'VB.NET
Dim RandomNumber As Integer
RandomNumber = RandomClass.Nex t()
The value of RandomNumber will, therefore, be assigned a random whole
number between 1 and 2,147,483,647.
In most coding situations, it is more desirable to create a random
number within a certain size range. In this case, the Next method should
be called with two arguments: the minimum value and the maximum value.
For example, the following assigns RandomNumber to a value that is
greater or equal to 4 and less than 14:
'VB.NET
Dim RandomNumber As Integer
RandomNumber = RandomClass.Nex t(4, 14)
Note that an ArgumentOutOfRa ngeException will be raised if the minimum
value is larger than the maximum value.
It is also possible to specify just the maximum value using a different
constructor. The following will return a return a random integer that is
greater or equal to 0 and less than 14:
'VB.NET
Dim RandomNumber As Integer
RandomNumber = RandomClass.Nex t(14)
Again, an ArgumentOutOfRa ngeException will be raised if the maximum
value is smaller than 0.