0

I want to pick some uniq numbers from a list of numbers randomly list of numbers:

dim firstlist() = [1,2,3,6,7,9,12,16]

I want to pick some uniq numbers randomly from this list

[2,6,16]
Jacob
  • 41,721
  • 6
  • 79
  • 81
sadeghhp
  • 621
  • 14
  • 28
  • possible duplicate of [C#: Is using Random and OrderBy a good shuffle algorithm?](http://stackoverflow.com/questions/1287567/c-is-using-random-and-orderby-a-good-shuffle-algorithm) – Jon Skeet Jul 12 '11 at 16:49
  • 2
    (The question I've linked to isn't actually the closest duplicate *question*, but it's got the most relevant *answer* IMO :) – Jon Skeet Jul 12 '11 at 16:50
  • @Jon: And I guessed correctly who the author of that answer was. :) – John Jul 12 '11 at 16:52

2 Answers2

0

like this?

        Dim firstlist() = {1, 2, 3, 6, 7, 9, 12, 16}
    Dim seclist As New Collection
    Dim rnd As New Random
    Debug.WriteLine("__")
    Dim i As Integer = 1
    While i <= 3
        Dim j As Integer = CInt(rnd.Next(0, firstlist.Length - 1))
        If Not seclist.Contains(j) Then
            seclist.Add(firstlist(j), j)
            Debug.WriteLine(CStr(firstlist(j)))
            i += 1
        End If
    End While
    'seclist now contains 3 values (data) and the indices (key)
Martin
  • 1,430
  • 10
  • 19
0
Dim firstlist = {1, 2, 3, 6, 7, 9, 12, 16}  
dim secondlist as new list(of integer)  
dim rand as new random()  
while not secondlist.count = 3  
    secondlist.add(firstlist(rand.next(firstlist.count-1)))  
end while
Qqbt
  • 802
  • 2
  • 8
  • 33