comList
is a list of strings (let us say 100), I want to draw eight strings out of the list randomly and save them into a new list. This is what I did.
Dim rnd As New Random()
For i As Integer = 0 To 7
_rndString.Add(comList.Item(rnd.Next(1, 8)))
Next
Looking into the new list is saw duplicates. That is since the Random Class
draws with replacement.
Let us say I have 4 strings: a,b,c,d
and I draw 3 randomly I can get the following resultset:
a,a,a
What is happening her. I draw a
and a
is put back into the pool of strings, so it is possible that I draw it again (shuffeling the pool doesnt help here since I still have a possibility to draw the same string). That is what rnd.Next(1,8) does, it draws a random number up to 8 but in the next draw you can draw it again.
I checked the Random Class
but couldnt find a method for drawing without replacement. Does anyone knows if there is a Class in .NET
that implements a drawing without replacement or how I can get this done?