i want to generate a matrix of 0's and 1's which is random every time plz hlp...!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vineet1987
    New Member
    • Nov 2009
    • 5

    i want to generate a matrix of 0's and 1's which is random every time plz hlp...!!

    i want to generate a series of random numbers like

    00101
    01011
    01111
    01010
    11101

    it is a 5*5 matrix and is random every time upon execution
    my code is:-


    Private Sub Command1_Click( )

    Call Randomize
    Dim x As Integer, y As Integer, z As Integer, t As Integer, s As Integer
    Dim i As Integer, k As Integer
    x = 0 + Int(2 * Rnd())

    y = 0 + Int(2 * Rnd())

    z = 0 + Int(2 * Rnd())
    t = 0 + Int(2 * Rnd())

    s = 0 + Int(2 * Rnd())
    Print x, y, z, t, s

    End Sub

    but i have to click on command button each time to generate a random 0's and 1's and i want to print random 5*5 matrix in a single click as said above but in this code when i m clicking the command button i m getting a 1*5 random matrix and i have to click again and again.....can i use goto control and send the cursor to initialize again and again and print till i get a 5*5 matrix or use for loop.. but i have tried everything and it isn't working....plea se help me get 5*5 random matrix of 0's and 1's.......
  • vb5prgrmr
    Recognized Expert Contributor
    • Oct 2009
    • 305

    #2
    Use a nested for loop structure...
    Code:
    Dim OuterForLoopCounter As Integer, InnerForLoopCounter As Integer
    Dim Result As Integer, MyMatrix(1 To 5, 1 To 5) As Integer
    For OuterForLoopCounter = 1 To 5
      For InnerForLoopCounter = 1 To 5
        Result = Int(2 * Rnd)
        MyMatrix(OuterForLoopCounter, InnerForLoopCounter) = Result
      Next InnerForLoopCounter
    Next OuterForLoopCounter


    Good Luck

    Comment

    Working...