469,090 Members | 1,217 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,090 developers. It's quick & easy.

Random Array

cindy2
35
The next code produces a random 9 by 9 array. It produces exactly one "1" in each row and column: So there are never two or more "1" 's in a row or column:

Expand|Select|Wrap|Line Numbers
  1. Dim j As Integer
  2.         Dim k As Integer
  3.         Dim i As Integer = 0
  4.  
  5.         Dim Rooster(8, 8) As Integer
  6.         j = Int(Rnd() * 9)
  7.         Rooster(j, i) = 1
  8.  
  9.         For i = 1 To 8
  10.             j = Int(Rnd() * 9)
  11.             k = 0
  12.             Rooster(j, i) = 1
  13.             Do
  14.                 Do While Rooster(j, i) = Rooster(j, k)
  15.                     Rooster(j, i) = 0
  16.                     j = Int(Rnd() * 9)
  17.                     Rooster(j, i) = 1
  18.                     k = 0
  19.                 Loop
  20.                 k = k + 1
  21.                 If k = i Then Exit Do
  22.             Loop
  23.         Next
  24.  
  25.  
The next thing I want to do, is adding the numbers 2 in the same way (ofcourse without overwriting the "1" 's). Does somebody know how?

Cindy
Sep 27 '07 #1
0 830

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Keith Griffiths | last post: by
10 posts views Thread by Virus | last post: by
16 posts views Thread by Jason | last post: by
10 posts views Thread by Johnny Snead | last post: by
5 posts views Thread by jar13861 | last post: by
7 posts views Thread by Brian | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by kglaser89 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.