Skip to content

Instantly share code, notes, and snippets.

@aloon
Last active December 12, 2015 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aloon/4771179 to your computer and use it in GitHub Desktop.
Save aloon/4771179 to your computer and use it in GitHub Desktop.
get UniqueRandomNumbers
Private Shared Function UniqueRandomNumbers(NumAleatories As Integer, elements As Integer) As List(Of Integer)
Dim aleatorios As New List(Of Integer)
If elements > 0 Then
Dim temp As List(Of Integer) = Enumerable.Range(0, elements)
If NumAleatories > elements Then
aleatorios = temp.OrderBy(Function(a) Guid.NewGuid())
Else
Dim r As New Random(DateTime.Now.Millisecond)
For i As Integer = 0 To NumAleatories - 1
Dim start As Integer = r.Next(0, temp.Count - 1)
aleatorios.Add(temp(start))
temp.RemoveAt(start)
Next
End If
End If
Return aleatorios
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment