Connecting Tech Pros Worldwide Help | Site Map

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

Newbie
 
Join Date: Nov 2009
Posts: 5
#1: 2 Weeks Ago
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....please help me get 5*5 random matrix of 0's and 1's.......
Newbie
 
Join Date: Oct 2009
Posts: 28
#2: 2 Weeks Ago

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


Use a nested for loop structure...
Expand|Select|Wrap|Line Numbers
  1. Dim OuterForLoopCounter As Integer, InnerForLoopCounter As Integer
  2. Dim Result As Integer, MyMatrix(1 To 5, 1 To 5) As Integer
  3. For OuterForLoopCounter = 1 To 5
  4.   For InnerForLoopCounter = 1 To 5
  5.     Result = Int(2 * Rnd)
  6.     MyMatrix(OuterForLoopCounter, InnerForLoopCounter) = Result
  7.   Next InnerForLoopCounter
  8. Next OuterForLoopCounter
  9.  


Good Luck
Reply