Represents a pseudo-random number generator, a device that produces a sequence of numbers that meet certain statistical requirements for randomness.

So the numbers you'll get will be "random enough" even though they aren't actually random. Never mind, let's start.

To create a random generator we just uses the data type Random, like so:

Dim r As New Random

To then get a random positive integer number within the span of an integer value in VB.NET use:

r.Next()

But you have to be careful if you want to generate more then one random number, if you do like this all numbers will be the same:

For i As Integer = 0 To 99

Dim r As New Random

r.Next()

Next

To make them all different you have to do this:

Dim r As New Random

For i As Integer = 0 To 99

r.Next()

Next

Even though we're doing this the 100 numbers will be "random" but if we call the function(or where we now have this code) again, the numbers won't be the same as before but they could look a bit like them(all depending on how often and when we calls the function(or whatever it is) again, but they could look very much the same). So therefor I recommend you to declare it as "unlocal" as you can to get the "most random" result, like this:

Public Class frmMain

Dim r As New Random

Private Sub mySub()

For i As Integer = 0 To 99

r.Next()

Next

End Sub

End Class

An example on this could be an old code I made which took a lot of puzzle pieces and randomized there positions, It added one piece at a random interval too but when I randomized its position I declared a new Random generator each time which resulted in this (It doesn't look so random, right? ):

[ATTACH]2315[/ATTACH]

You can also set a exclusive maximal value the Random Generator can generate, like this:

r.Next(11)

Or both the inclusive minimal value and the exclusive maximal:

r.Next(5, 11)

Or if you want to get a Double value instead on an Integer you can use NextDouble(), then you'll receive a "random" number between 0.0 and 1.0, you can't change the minimal value and maximal value when using NextDouble. So NextDouble simply looks like this:

r.NextDouble()

This was it, remember that none of the random numbers you'll get will be completely random no matter how many times you're using the number generators to get only one number, but they are very often "random enough". Hope you enjoyed this tutorial