Imports System
Imports System.Collections.Generic
' To fill a 3x3 grid to be a valid Sudoku grid, you must ensure that each row,
' column, and the 3x3 grid contains the numbers 1 through 9 without repetition.
Module SudokuGridGenerator
Private Const SIZE As Integer = 3
' Function to shuffle an array
Private Sub Shuffle(ByRef numbers As List(Of Integer))
Dim rnd As New Random()
For i As Integer = numbers.Count - 1 To 1 Step -1
Dim j As Integer = rnd.Next(i + 1)
Dim temp As Integer = numbers(i)
numbers(i) = numbers(j)
numbers(j) = temp
Next
End Sub
' Function to fill the Sudoku grid
Private Sub FillSudokuGrid(ByRef grid As Integer(,))
Dim numbers As New List(Of Integer) From {1, 2, 3, 4, 5, 6, 7, 8, 9}
' Shuffle the numbers randomly
Shuffle(numbers)
' Fill the 3x3 grid row by row
Dim index As Integer = 0
For i As Integer = 0 To SIZE - 1
For j As Integer = 0 To SIZE - 1
grid(i, j) = numbers(index)
index += 1
Next
Next
End Sub
' Function to print the grid
Private Sub PrintGrid(ByVal grid As Integer(,))
For i As Integer = 0 To SIZE - 1
For j As Integer = 0 To SIZE - 1
Console.Write(grid(i, j) & " ")
Next
Console.WriteLine()
Next
End Sub
Sub Main()
' Initialize an empty 3x3 grid
Dim grid(SIZE - 1, SIZE - 1) As Integer
' Fill the grid with a valid Sudoku configuration
FillSudokuGrid(grid)
' Print the grid
Console.WriteLine("Generated 3x3 Sudoku Grid:")
PrintGrid(grid)
End Sub
End Module
' run
'
' Generated 3x3 Sudoku Grid:
' 5 3 7
' 8 6 2
' 4 9 1
'