VBMath Microsoft.VisualBasic.dll Rnd()

Usage

For random numbers generated using Rnd() from VBMath.

Generator

Seed:
Internal Integer Seed:
Negative Single:
"Initial" Double:

Seed Range

Negative Single (32-bit) or Double (64-bit)
Seed Size: 24 bits
Default Seed: 327680
Shortest-Possible Seed (Single): -0.03247
Shortest-Possible Seed (Double): 33327 / 66655
* Randomize(Double) modifies the previous seed but not overrides *

Definition

LCG
X0 = Seed (Using converted integer seed)
Xn+1 = (1140671485 Xn + 12820163) mod 16777216
Initial Output: X1
Output: X / 16777216
Range: 0 ~ 1 (16777215 / 16777216)

Sample Code for 100 Values (vb.net):

Negative Single version:
Module Module1
    Sub Main(ByVal args As String())
        If args.Length >= 1 Then
            Console.Write(Rnd(Val(args(0))) & " ")
        Else
            Console.Write(Rnd() & " ")
        End If
        For i As Integer = 1 To 99
            Console.Write(Rnd() & " ")
        Next
        Console.WriteLine()
    End Sub
End Module
			
Double version (Notice that it may produce different result if the Randomize below is not the first called one since the execution):
Module Module1
    Sub Main(ByVal args As String())
        If args.Length >= 1 Then
            Randomize(Val(args(0)))
        End If
        For i As Integer = 1 To 100
            Console.Write(Rnd() & " ")
        Next
        Console.WriteLine()
    End Sub
End Module