Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,945 questions

51,887 answers

573 users

How to initialize a matrix with random characters in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Friend Const ROWS As Integer = 3
    Friend Const COLS As Integer = 4

    Public Shared Sub printMatrix(ByVal matrix As Char(,))
        For i As Integer = 0 To ROWS - 1
            For j As Integer = 0 To COLS - 1
                Console.Write("{0,3}", matrix(i, j))
            Next
            Console.WriteLine()
        Next
    End Sub

    Public Shared Sub initializeMatrixWithRandomCharacters(ByVal matrix As Char(,))
        Dim characters As String = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
        
        Dim rand As Random = New Random()

        For i As Integer = 0 To ROWS - 1
            For j As Integer = 0 To COLS - 1
                matrix(i, j) = characters(rand.[Next](characters.Length))
            Next
        Next
    End Sub

    Public Shared Sub Main(ByVal args As String())
        Dim matrix As Char(,) = New Char(2, 3) {}
        
        initializeMatrixWithRandomCharacters(matrix)
        
        printMatrix(matrix)
    End Sub
End Class

 
 
 
' run:
'
'  m  y  i  2
'  L  8  F  A
'  F  H  h  J
'

 



answered May 18, 2024 by avibootz
...