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,923 questions

51,856 answers

573 users

How to fill an array with 1 and 0 in random locations with VB.NET

1 Answer

0 votes
Imports System

Public Class FillArrayWith1And0InRandomLocations
	Public Shared Sub FillArrayWithRandom1and0(ByVal array As Integer())
        Dim rand As Random = New Random()
        Dim len As Integer = array.Length

        For i As Integer = 0 To len - 1
            array(i) = rand.Next(2) ' Generates either 0 or 1
        Next
    End Sub

    Public Shared Sub Main(ByVal args As String())
        Dim size As Integer = 10
        Dim array As Integer() = New Integer(size - 1) {}

        FillArrayWithRandom1and0(array)

        For Each num As Integer In array
            Console.Write(num & " ")
        Next
    End Sub
End Class



' run:
'
' 1 1 1 0 1 0 1 0 0 1 
'

 



answered Jan 25, 2025 by avibootz

Related questions

1 answer 59 views
1 answer 83 views
1 answer 81 views
1 answer 77 views
1 answer 75 views
...