We found a way to make our random seed more complex with the
RNGCryptoServiceProvider
We made a function like this:
Public Function randomSelect(ByVal min As Integer, ByVal max As Integer) As Integer
Dim rng As New RNGCryptoServiceProvider()
Dim buffer As Byte() = New Byte(3) {}
rng.GetBytes(buffer)
Dim result As Integer = BitConverter.ToInt32(buffer, 0)
Return New Random(result).[Next](min, max)
End Function
With the seed being random it provides a more pure randomness
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Collections.Generic
Imports System.Security.Cryptography
Public empList As List(Of Integer)
Public daysList As List(Of DateTime)
Public Sub generateRandom()
Dim tecnInDaysHash As New HashSet(Of TecnInDays)
Dim randEmployeeIndex, selectedEmpId As integer
randEmployeeIndex = randomSelect(1, empList.Count)
randDayIndex = randomSelect(1, daysList.Count)
selectedEmpId = empList.Item(randEmployeeIndex)
selectedDayDate = daysList.Item(randDayIndex)
Dim tinObj As New TecnInDays
tinObj.Days = selectedDayDate.Day
tinObj.IdTecn = selectedEmpId
If Not (tecnInDaysHash.Add(tinObj)) Then
randEmployeeIndex = randomSelect(1, empList.Count)
selectedEmpId = empList.Item(randEmployeeIndex)
End If
End Sub
We create a little class to identify duplicates
Imports Microsoft.VisualBasic
Public Class TecnInDays
Private _IdTecn, _Days As Integer
Public Property IdTecn() As Integer
Get
Return _IdTecn
End Get
Set(ByVal value As Integer)
_IdTecn = value
End Set
End Property
Public Property Days() As Integer
Get
Return _Days
End Get
Set(ByVal value As Integer)
_Days = value
End Set
End Property
End Class
Hope this helps to anyone that stumble upon this.