Hi there,
For a school project I need to create a Bingo game based on a 2D Array.
Just like a real Bingo card the numbers need to be unique.
I managed to create a card with random numbers as shown in the code below, but I have no clue how to generate unique random numbers.
Any suggestions?
For a school project I need to create a Bingo game based on a 2D Array.
Just like a real Bingo card the numbers need to be unique.
I managed to create a card with random numbers as shown in the code below, but I have no clue how to generate unique random numbers.
Any suggestions?
Code:
Public NotInheritable Class MainPage
Inherits Page
Dim BingoArray(7, 7) As Short
Dim generator As New Random
Dim size As Integer
Private Sub generateCardBtn_Click(sender As Object, e As RoutedEventArgs) Handles generateCardBtn.Click
Dim i As Integer 'amount rows (first dimension)
Dim j As Integer 'amount collumns (2nd dimension)
Dim k As Integer 'rows & collumns size
Dim minVal As Integer
Dim maxVal As Integer
Dim randNum As Integer
If twentyfiveRdBtn.IsChecked Then
size = 25
k = Math.Sqrt(size)
ReDim BingoArray(k, k) 'Redim card size
For i = 0 To BingoArray.GetUpperBound(0) - 1 'preserve one row in card / first dimension
For j = 0 To BingoArray.GetUpperBound(1) - 1 'preserve one row in card / second dimension
minVal = (i * 10) + 10
maxVal = (i * 10) + 20 - 1
randNum = generator.Next(minVal, maxVal)
BingoArray(i, j) = randNum
bingoCardTxtBox.Text += BingoArray(i, j) & " "
Next
bingoCardTxtBox.Text += vbNewLine
Next
End If
End Sub
End Class