I hope I didn't step on your toes dunfiddlin by explaining your code.
Is this OK Providence?
Define variable called RdI as a Random Type variable.
Code:
Dim RdI As New Random
Define a List Variable to hold the integers that you need before shuffling.
Code:
Dim LofI As List (Of Int16) = New List (Of Int16) From {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
Create a new list ready to hold the shuffled numbers
Code:
Dim Shuffle As List(Of Int16) = New List(Of Int16)
LofI.Count gives the number of entries in the list LofI. We repeat this number of times. We have to go backwards in the loop (Step -1) because we will be deleting one from the list every time it loops.
The loop consists of:
Take a random number based on the maximum number of entries in the list
Use that number as an index in the list of integers (LofI) and add the value in that index to the list of shuffled numbers
Remove the integer we used from the list of integers LofI so that it cannot be selected again. (This is why dunfiddlin said his code (and mine) could never repeat an integer)
Code:
For i = LofI.Count To 1 Step -1
Idx=RdI.Next(1,i) -1
Shuffle.Add(LofI(idx))
LofI.RemoveAt(idx)
Next
We are now in a position where we have all the integers in the original list in a random order in the new list Shuffle.
Create an array of the buttons on the form
Code:
Dim buttons = Controls.OfType(Of Button) ().ToList
Remove Button 16 because you only need to use 15 of them
Code:
Buttons.Remove(Button16)
We now only need a simple For-Next loop because the numbers in the list are now random. It takes each each entry in the list in turn and sets the respective button text accordingly.
Code:
For i = Shuffle.Count – 1
Buttons(i).Text = Shuffle(i).ToString
Next