Master_Splinter
New Member
- Joined
- Feb 14, 2013
- Messages
- 3
I have been using this great website for a while, but I finally came across something that has stumped me, and I haven't seen in other posts.
So here is my first post.
So I have code that 'works', but I feel like it could be better. (And to be usable, it has to be)
My problem involves a large array (3000 columns by 5000 rows)
What I'm looking for is an efficient way to randomize the items in each row.
so array1 = [1,2,3,4;5,6,7,8] could become array1 = [3,2,4,1; 7,6,5,8] (or something similar)
My solution now is to shuffle the array in place.
I iterate though the array, pick a random member of the row and swap them.
'code
'buys is defined earlier as buys(1 to 5000,1 to 3000) as integer
dim i as integer
dim j as integer
dim k as integer
dim rndm as integer
for i = 1 to 5000
For j = 1 To 3000
k = buys(i, j)
rndm = Floor(Rnd * 3000, 1) + 1
buys(i, j) = buys(i, rndm)
buys(i, rndm) = k
Next j
next i
'end code
So this works, but it seems to take longer than I would suspect.
My guess is there is a performance hit from all the buys(i,j) references and such, but I'm not sure.
I tried setting rdmn to a const like 1, and that didn't affect performance, so I don't think its the rnd function.
Any ideas on how to speed this up?
Thank you,
-Dave
So here is my first post.
So I have code that 'works', but I feel like it could be better. (And to be usable, it has to be)
My problem involves a large array (3000 columns by 5000 rows)
What I'm looking for is an efficient way to randomize the items in each row.
so array1 = [1,2,3,4;5,6,7,8] could become array1 = [3,2,4,1; 7,6,5,8] (or something similar)
My solution now is to shuffle the array in place.
I iterate though the array, pick a random member of the row and swap them.
'code
'buys is defined earlier as buys(1 to 5000,1 to 3000) as integer
dim i as integer
dim j as integer
dim k as integer
dim rndm as integer
for i = 1 to 5000
For j = 1 To 3000
k = buys(i, j)
rndm = Floor(Rnd * 3000, 1) + 1
buys(i, j) = buys(i, rndm)
buys(i, rndm) = k
Next j
next i
'end code
So this works, but it seems to take longer than I would suspect.
My guess is there is a performance hit from all the buys(i,j) references and such, but I'm not sure.
I tried setting rdmn to a const like 1, and that didn't affect performance, so I don't think its the rnd function.
Any ideas on how to speed this up?
Thank you,
-Dave