So as a mild musing, I made a shared class for making random numbers. Only
I am using the hashcode of a guid as my seed.
Public NotInheritable Class SimpleRandomizer
Private Shared pintSeed As Integer
Shared Sub New()
Dim g As Guid
g = System.Guid.NewGuid
pintSeed = g.GetHashCode
Randomize(CType(pintSeed, Double))
End Sub
Public Shared Function GetRandom(ByVal MaxValue As Integer, ByVal MinValue
As Integer) As Integer
'Test values
If MaxValue < 0 Then Throw New RandomizerException("Max value must be
greater than 0.", New RandomizerException.RandomizerInputs(pintSeed,
MaxValue, MinValue))
If MaxValue < 0 Then Throw New RandomizerException("Min value must be
greater than 0.", New RandomizerException.RandomizerInputs(pintSeed,
MaxValue, MinValue))
If MaxValue < MinValue Then Throw New RandomizerException("Min value
must be greater than 0.", New RandomizerException.RandomizerInputs(pintSeed,
MaxValue, MinValue))
Try
Return CInt(Int((MaxValue - MinValue + 1) * Rnd() + MinValue))
Catch ex As Exception
Throw New RandomizerException("Failed to generate random number", ex,
New RandomizerException.RandomizerInputs(pintSeed, MaxValue, MinValue))
End Try
End Function
Public Class RandomizerException
Inherits System.ApplicationException
Public Structure RandomizerInputs
Private pintSeed As Integer
Private pintUpperbound As Integer
Private pintLowerbound As Integer
Public Sub New(ByVal Seed As Integer, ByVal Upperbound As Integer,
ByVal Lowerbound As Integer)
pintSeed = Seed
pintUpperbound = Upperbound
pintLowerbound = Lowerbound
End Sub
Public ReadOnly Property Seed()
Get
Return pintSeed
End Get
End Property
Public ReadOnly Property Upperbound() As Integer
Get
Return pintUpperbound
End Get
End Property
Public ReadOnly Property Lowerbound() As Integer
Get
Return pintLowerbound
End Get
End Property
Public Overrides Function ToString() As String
Return String.Format("Seed: {0}, Upperbound: {1}, Lowerbound: {0}",
Seed, Upperbound, Lowerbound)
End Function
End Structure
Private pobjInputs As RandomizerInputs
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal message As String)
MyBase.New(message)
End Sub
Public Sub New(ByVal message As String, ByVal innerException As
Exception)
MyBase.New(message, InnerException)
End Sub
Public Sub New(ByVal Inputs As RandomizerInputs)
MyBase.New()
pobjInputs = Inputs
End Sub
Public Sub New(ByVal message As String, ByVal Inputs As
RandomizerInputs)
MyBase.New(message)
pobjInputs = Inputs
End Sub
Public Sub New(ByVal message As String, ByVal innerException As
Exception, ByVal Inputs As RandomizerInputs)
MyBase.New(message, innerException)
pobjInputs = Inputs
End Sub
Public ReadOnly Property Inputs() As RandomizerInputs
Get
Return pobjInputs
End Get
End Property
Public Overrides Function ToString() As String
Return MyBase.ToString & vbCrLf & "Inputs:" & vbCrLf & Inputs.ToString
End Function
End Class
End Class