You miss the condition part.
Try something like this.
int i = 0;
var random = new Random();
var randomList = new List<int>();
while (i < 5) {
int x = random.Next(1, 15);
if (!randomList.Contains(x) || !randomList.Contains((x + 1)) || !randomList.Contains((x - 1))) {
randomList.Add(i);
++i;
}
}
randomList.ForEach(r => cmbRnd.Items.Add(r.ToString()));
VB
Dim i As Integer = 0
Dim random = New Random()
Dim randomList = New List(Of Integer)()
While i < 5
Dim x As Integer = random.[Next](1, 15)
If Not randomList.Contains((x + 1)) OrElse Not randomList.Contains((x - 1)) OrElse Not randomList.Contains(x) Then
randomList.Add(i)
i += 1
End If
End While
randomList.ForEach(Function(r) cmbRnd.Items.Add(r.ToString()))
Hope it helps for your assignment.
<edit>
The important part is the condition
List should
not contain (random or random+1 or random-1)