Question : Random numbers in VB.net not random...weird?

This is related to the last question I wrote about generating random numbers in VB.NET, but I'll repost the details, here, too.

I need to generate six unique random numbers between 7 and 20 for a dart board application that I'm writing.  It's to simulate wildcard cricket, for those that are familiar.

The code that I have seemingly generates random numbers, but something I've done or some aspect of the random number generator is making the results pretty far from random.  The following code results in the exact same sequence of numbers every time my sub is called.  Each time I re-run the sub, it generates new numbers, but it's always the same numbers, for example:

first refresh results 9,15,16,17,10,7
second refresh results 18,13,12,15,8,7
third refresh results 11,18,19,13,10,8
fourth refresh results 12,9,7,13,16,11
...and so on

It's like this every single time I run the app, the same numbers in the same sequence.  I tried it with one rnd and with one for each intSlot var (as in the sample code), but the results are exactly the same either way.

My guess, since I'm not a very good coder, is that it has to do with my logic that tries to pick unique numbers, but it's so weird that it does the same numbers each time that I just can't tell for sure.

So, any guidance would be much appreciated.  EE has been awesome with this...couldn't have gotten this far without it!

Here's the code:
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
Public Sub GenWildCard()

        'initialize random number generator
        Static rnd1 As New Random(20)
        Static rnd2 As New Random(20)
        Static rnd3 As New Random(20)
        Static rnd4 As New Random(20)
        Static rnd5 As New Random(20)
        Static rnd6 As New Random(20)

        If Not intSlot1Lock = 1 Then

            intSlot1 = rnd1.Next(7, 20)
            If intSlot1 = intSlot5 Or intSlot1 = intSlot4 Or intSlot1 = intSlot3 Or intSlot1 = intSlot6 Or intSlot1 = intSlot2 Then
                Do Until intSlot1 <> intSlot5 And intSlot1 <> intSlot4 And intSlot1 <> intSlot3 And intSlot1 <> intSlot6 And intSlot1 <> intSlot2

                    intSlot1 = rnd1.Next(7, 20)
                Loop
            End If
            lblSlot1.Text = intSlot1
        End If

        If Not intSlot2Lock = 1 Then
            intSlot2 = rnd2.Next(7, 20)
            If intSlot2 = intSlot5 Or intSlot2 = intSlot4 Or intSlot2 = intSlot3 Or intSlot2 = intSlot6 Or intSlot2 = intSlot1 Then
                Do Until intSlot2 <> intSlot5 And intSlot2 <> intSlot4 And intSlot2 <> intSlot3 And intSlot2 <> intSlot6 And intSlot2 <> intSlot1

                    intSlot2 = rnd2.Next(7, 20)
                Loop
            End If
            lblSlot2.Text = intSlot2
        End If

        If Not intSlot3Lock = 1 Then
            intSlot3 = rnd3.Next(7, 20)
            If intSlot3 = intSlot5 Or intSlot3 = intSlot4 Or intSlot3 = intSlot6 Or intSlot3 = intSlot2 Or intSlot3 = intSlot1 Then
                Do Until intSlot3 <> intSlot5 And intSlot3 <> intSlot4 And intSlot3 <> intSlot6 And intSlot3 <> intSlot2 And intSlot3 <> intSlot1

                    intSlot3 = rnd3.Next(7, 20)
                Loop
            End If
            lblSlot3.Text = intSlot3
        End If

        If Not intSlot4Lock = 1 Then
            intSlot4 = rnd4.Next(7, 20)
            If intSlot4 = intSlot5 Or intSlot4 = intSlot6 Or intSlot4 = intSlot3 Or intSlot4 = intSlot2 Or intSlot4 = intSlot1 Then
                Do Until intSlot4 <> intSlot5 And intSlot4 <> intSlot6 And intSlot4 <> intSlot3 And intSlot4 <> intSlot2 And intSlot4 <> intSlot1

                    intSlot4 = rnd4.Next(7, 20)
                Loop
            End If
            lblSlot4.Text = intSlot4
        End If

        If Not intSlot5Lock = 1 Then
            intSlot5 = rnd5.Next(7, 20)
            If intSlot5 = intSlot6 Or intSlot5 = intSlot4 Or intSlot5 = intSlot3 Or intSlot5 = intSlot2 Or intSlot5 = intSlot1 Then
                Do Until intSlot5 <> intSlot6 And intSlot5 <> intSlot4 And intSlot5 <> intSlot3 And intSlot5 <> intSlot2 And intSlot5 <> intSlot1
                    intSlot5 = rnd5.Next(7, 20)
                Loop
            End If
            lblSlot5.Text = intSlot5
        End If

        If Not intSlot6Lock = 1 Then
            intSlot6 = rnd6.Next(7, 20)
            If intSlot6 = intSlot5 Or intSlot6 = intSlot4 Or intSlot6 = intSlot3 Or intSlot6 = intSlot2 Or intSlot6 = intSlot1 Then
                Do Until intSlot6 <> intSlot5 And intSlot6 <> intSlot4 And intSlot6 <> intSlot3 And intSlot6 <> intSlot2 And intSlot6 <> intSlot1
                    intSlot6 = rnd6.Next(7, 20)
                Loop
            End If
            lblSlot6.Text = intSlot6
        End If

    End Sub

Answer : Random numbers in VB.net not random...weird?

By always specifying 20 as your seed, you will always get the same sequence.  If you simply omit the 20 (ie, use Random by itself), the system will use a time-based seed.

You should also consider having a single instance of Random instead of six instances.  It will probably simplify your code quite a bit.
Random Solutions  
 
programming4us programming4us