Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,037 questions

40,897 answers

573 users

How to select N reservoir items randomly from a list in VB.NET

1 Answer

0 votes
Imports System
Imports System.Linq
Imports System.Collections.Generic

Public Class Program
    Public Shared Sub Main(ByVal args As String())
        Dim list = New List(Of Integer) From {4, 9, 14, 96, 13, 0, 3, 99, 19, 2, 80, 1, 7}
        Dim N As Integer = 5
        
		Dim rand As Random = New Random()
		
        Dim reservoir = list.OrderBy(Function(x) rand.[Next]()).Take(N)
	
        Console.WriteLine(String.Join(" "c, reservoir))
    End Sub
End Class





' run:
'
' 99 0 80 19 1
'

 





answered Feb 3 by avibootz
...