Last active
December 12, 2015 12:19
-
-
Save aloon/4771179 to your computer and use it in GitHub Desktop.
get UniqueRandomNumbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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