Hello, I am trying to make a random number generator (its not really a random number generator, more a random order generator) that puts the numbers 1, 14 in a random order, without duplicating the numbers. That is the problem I am having it will often select the same number once or twice (presumably because of the limited range)

My tutor has suggested to do it using an array, and 2 loops however, I cannot seem to find a way of doing that, so I have attempted it my own way, though no luck.

If anyone can point me in the right direction I would be very grateful.

Here is my code

Public Class Stations
    Dim RDN As Random
    Dim total As Integer
    Dim Value As Integer
    Dim stid1, stid2, stid3, stid4, stid5, stid6, stid7, stid8, stid9, stid10, stid11, stid12, stid13, stid14 As Integer


    Private Sub Stations_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        RDN = New Random
        Debug.Text = 0
        tbtotal.Text = 0

    End Sub


    Private Sub bRandom_Click(sender As System.Object, e As System.EventArgs) Handles bRandom.Click
        stid1 = RDN.Next(1, 15)
        stid2 = RDN.Next(1, 15)
        stid3 = RDN.Next(1, 15)
        stid4 = RDN.Next(1, 15)
        stid5 = RDN.Next(1, 15)
        stid6 = RDN.Next(1, 15)
        stid7 = RDN.Next(1, 15)
        stid8 = RDN.Next(1, 15)
        stid9 = RDN.Next(1, 15)
        stid10 = RDN.Next(1, 15)
        stid11 = RDN.Next(1, 15)
        stid12 = RDN.Next(1, 15)
        stid13 = RDN.Next(1, 15)
        stid14 = RDN.Next(1, 15)

        tbstid1.Text = stid1.ToString
        tbstid2.Text = stid2.ToString
        tbstid3.Text = stid3.ToString
        tbstid4.Text = stid4.ToString
        tbstid5.Text = stid5.ToString
        tbstid6.Text = stid6.ToString
        tbstid7.Text = stid7.ToString
        tbstid8.Text = stid8.ToString
        tbstid9.Text = stid9.ToString
        tbstid10.Text = stid10.ToString
        tbstid11.Text = stid11.ToString
        tbstid12.Text = stid12.ToString
        tbstid13.Text = stid13.ToString
        tbstid14.Text = stid14.ToString
        Do While tbtotal.Text <> total
            If tbstid2.Text = tbstid1.Text Then
                tbstid2.Clear()
                tbstid2.Text = stid2
            ElseIf tbstid3.Text = tbstid2.Text Or tbstid1.Text Then
                tbstid3.Clear()
                tbstid3.Text = stid3
            ElseIf tbstid4.Text = tbstid3.Text Or tbstid2.Text Or tbstid1.Text Then
                tbstid4.Clear()
                tbstid4.Text = stid4
            ElseIf tbstid5.Text = tbstid4.Text Or tbstid3.Text Or tbstid2.Text Or tbstid1.Text Then
                tbstid5.Clear()
                tbstid5.Text = stid5
            ElseIf tbstid6.Text = tbstid5.Text Or tbstid4.Text Or tbstid3.Text Or tbstid2.Text Or tbstid1.Text Then
                tbstid6.Clear()
                tbstid6.Text = stid6
            ElseIf tbstid7.Text = tbstid6.Text Or tbstid5.Text Or tbstid4.Text Or tbstid3.Text Or tbstid2.Text Or tbstid1.Text Then
                tbstid7.Clear()
                tbstid7.Text = stid7
            ElseIf tbstid8.Text = tbstid7.Text Or tbstid6.Text Or tbstid5.Text Or tbstid4.Text Or tbstid3.Text Or tbstid2.Text Or tbstid1.Text Then
                tbstid8.Clear()
                tbstid8.Text = stid8
            ElseIf tbstid9.Text = tbstid8.Text Or tbstid7.Text Or tbstid6.Text Or tbstid5.Text Or tbstid4.Text Or tbstid3.Text Or tbstid2.Text Or tbstid1.Text Then
                tbstid9.Clear()
                tbstid9.Text = stid9
            ElseIf tbstid10.Text = tbstid9.Text Or tbstid8.Text Or tbstid7.Text Or tbstid6.Text Or tbstid5.Text Or tbstid4.Text Or tbstid3.Text Or tbstid2.Text Or tbstid1.Text Then
                tbstid10.Clear()
                tbstid10.Text = stid10
            ElseIf tbstid11.Text = tbstid10.Text Or tbstid9.Text Or tbstid8.Text Or tbstid7.Text Or tbstid6.Text Or tbstid5.Text Or tbstid4.Text Or tbstid3.Text Or tbstid2.Text Or tbstid1.Text Then
                tbstid11.Clear()
                tbstid11.Text = stid11
            ElseIf tbstid12.Text = tbstid11.Text Or tbstid10.Text Or tbstid9.Text Or tbstid8.Text Or tbstid7.Text Or tbstid6.Text Or tbstid5.Text Or tbstid4.Text Or tbstid3.Text Or tbstid2.Text Or tbstid1.Text Then
                tbstid12.Clear()
                tbstid12.Text = stid12
            ElseIf tbstid13.Text = tbstid12.Text Or tbstid11.Text Or tbstid10.Text Or tbstid9.Text Or tbstid8.Text Or tbstid7.Text Or tbstid6.Text Or tbstid5.Text Or tbstid4.Text Or tbstid3.Text Or tbstid2.Text Or tbstid1.Text Then
                tbstid13.Clear()
                tbstid13.Text = stid13
            ElseIf tbstid14.Text = tbstid13.Text Or tbstid12.Text Or tbstid11.Text Or tbstid10.Text Or tbstid9.Text Or tbstid8.Text Or tbstid7.Text Or tbstid6.Text Or tbstid5.Text Or tbstid4.Text Or tbstid3.Text Or tbstid2.Text Or tbstid1.Text Then
                tbstid14.Clear()
                tbstid14.Text = stid14

            End If
        Loop

    End Sub 
End Class

Thank you in advance.

in the first instance create a control array of text boxes, put one text box on the form, copy and paste it, VB will ask if you want to create a control array to which you answer Yes. Then past the remaining 13 text boxes.

randomise
for i = 1 to 14
  textboxNo = int(rnd()*14)
  do until textbox(textboxNo).text = ""
     textboxNo = int(rnd()*14)
  loop
  textbox(TextboxNo).text = i
next i
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.