VB.NET - Tip - Generating Random Numbers

Random Number Function

Synopsis:

A simple function to return random numbers in a given range. A static declaration is made so that a new Random class is not generated and seeded every time the function is called.

The Code:

     Public Function RandomNumber(ByVal low As Int32, ByVal high As Int32) As Integer
        Static RandomNumGen As New System.Random
        Return RandomNumGen.Next(low, high+1)
    End Function

About this page: