Hey guys.
I've got the following code (variables declared previously):
This creates (in this case for my data, n=4) 4 numbers between 1 and 4 which have been swapped in a random fashion to create a random permutation.
What I want to achieve is a set of random numbers from i = 1 to n^2 (as opposed to from i = 1 to n). However, when I try to do this, the line which I have highlighted above gives error 9 (subscript out of range)
Sorry for this being such a pedestrian question, but how do I get around this?
I've got the following code (variables declared previously):
Code:
ReDim A(i) As Integer
For i = 1 To n
[COLOR=#ff0000] A(i) = i[/COLOR]
Next i
For i = 1 To n
r = Int((n - i + 1) * Rnd() + i)
y = A(i)
A(i) = A(r)
A(r) = y
Cells(i).Value = A(i)
Next i
This creates (in this case for my data, n=4) 4 numbers between 1 and 4 which have been swapped in a random fashion to create a random permutation.
What I want to achieve is a set of random numbers from i = 1 to n^2 (as opposed to from i = 1 to n). However, when I try to do this, the line which I have highlighted above gives error 9 (subscript out of range)
Sorry for this being such a pedestrian question, but how do I get around this?