Rnd Function in VB.NET

How to use the Rnd Function in VB.NET?


Rnd Function

Rnd(), Round Math Function in Visual Basic.net 2008 is used to return a random number of Single datatype.


In the above syntax Number for which the random number is generated, if this number not provided or greater than zero, the next random number in sequence is generated. If this number is less than zero, the same number is generated everytime, if equal to zero, the most recently generated number is returned.

Module Module1
Sub Main()
Console.WriteLine('Random number generated for -1 is::'
& Rnd(-1))
Console.WriteLine('Random number generated for 1 is::'
& Rnd(1))
End Sub
End Module

Random number generated for -1 is::0.224007
Random number generated for 1 is::0.03584582

In the above example, random numbers are generated for 1, -1 using the Rnd() round math function.

Visual Basic Tutorial

Ask Questions

Ask Question