Dim rng As New Random()
This declares an instance of the Random class called rng
. In this case, the current time at the point where the object is created is used to calculate the seed. This is the most common usage, but has its own problems as we shall see later in the remarks
Instead of allowing the program to use the current time as part of the calculation for the initial seed number, you can specify the initial seed number. This can be any 32 bit integer literal, constant or variable. See below for examples. Doing this means that your instance will generate the same sequence of pseudo-random numbers, which can be useful in certain situations.
Dim rng As New Random(43352)
or
Dim rng As New Random(x)
where x
has been declared elsewhere in your program as an Integer constant or variable.