|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
I've been playing with this 2 dimensional array for weeks and i think i've finally run out of ideas on what more to try. Basically it's a 2 dimensional array that i want to randomize by both rows and by columns. So looking either horizontally or vertically, i should not see any repeat numbers from 1-10. It works, but only in one way, either vert. or horiz. but not both ways (you can comment out the colgood = false or rowgood = false to see one of the pieces of code working, so currently colgood is disabled and so rows wise all the numbers should be unique) Could it be taking too long to process (script always times out) or is my code faulty ? thanks for looking and attempting, below is my code and below that is couple examples:
<% dim random_number(9,9) '(10 columns,10 rows) dim Rows, Columns, checkRows, checkColumns, colgood, rowgood randomize For Rows = 0 to 9 For Columns = 0 to 9 colgood = "true" rowgood = "true" random_number(Columns,Rows) = Int(Rnd * 10) + 1 for checkColumns= 0 to Columns - 1 if random_number(checkColumns, Rows)= random_number(Columns, Rows) then 'colgood = "false" end if next if colgood = "true" then for checkRows= 0 to Rows - 1 if random_number(Columns,checkRows) = random_number(Columns,Rows) then rowgood = "false" end if next end if if (colgood = "false" OR rowgood = "false") then Columns=Columns-1 end if next next For Rows = 0 to 9 For Columns = 0 to 9 response.write random_number(Columns,Rows) & " " next response.write("<br><br>") next %> here is the output when you comment out "colgood = false" (pick any column and you'll see random unique numbers from 1-10) 1 6 1 10 9 3 2 6 1 1 6 10 9 6 5 2 4 7 4 2 2 4 2 7 8 6 6 5 3 4 9 8 6 8 2 9 7 2 7 10 4 5 7 5 3 7 3 8 5 5 7 3 4 1 6 8 5 10 8 9 8 1 8 9 10 5 1 9 6 6 5 2 5 4 1 1 10 3 10 8 3 9 3 3 4 4 9 1 9 7 10 7 10 2 7 10 8 4 2 3 Comment: see how looking horizontally they repeat ? now here is the code when you disable the "rowgood=false" line: 8 2 10 7 5 3 1 6 4 9 2 10 7 5 1 6 4 9 3 8 10 3 2 4 8 1 6 5 9 7 9 10 4 8 2 7 3 6 5 1 3 9 7 8 10 6 4 1 2 5 5 8 7 3 2 1 9 4 10 6 3 7 6 5 9 8 10 2 4 1 8 5 7 1 2 9 10 6 3 4 1 4 5 8 7 10 3 6 9 2 5 3 6 10 9 7 1 4 8 2 Comment: now if you look horizontally, they're unique, but vertically they are repeating **i want it unique in both ways, no matter which row or column you choose** this is just my version of the algorithm, if anyone knows of a pre-existing one, please please let me know thanks much, -PS |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > ASP 2 dim array not working perfectly |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|