P
Pradip Jain
i have an array of unique numbers (say 50 rows and 1 column, all 50 cells
contain a unique number). I generate a new random number and want to check if
this new number is already present in this array. One way is to check cell by
cell to see if the new random number is equal to that cell value. this works
fine but is slow. I have to repeat this step several thousands time and it is
making a big difference in computation time. Is there a way by which i can
check the entire array at once to see if a particular value is present?
for example see my code below:
********************************
RandomRowLowerBound = 1
RandomRowUpperBound = 50
NewRandomStartLine:
Randomize
RandomRowGenerated = Int((RandomRowUpperBound - RandomRowLowerBound + 1) *
Rnd + RandomRowLowerBound)
For CounterNumber13 = 1 To RandomRowUpperBound
If RandomRowAlreadyGeneratedArray(CounterNumber13, 1) = RandomRowGenerated
Then
GoTo NewRandomStartLine
End If
Next CounterNumber13
RandomRowAlreadyGeneratedArray(CounterNumber14, 1) = RandomRowGenerated
********************************
Here the program generates a random number in between 1 and 50. Then it goes
on to check if that number has already been generated in a previous step. The
program has record of random numbers already generated in
RandomRowAlreadyGeneratedArray which is updated after each successful new
random number found. To repeat my query again - Is there a way by which i can
check the entire array at once to see if a particular value is present?
TIA
contain a unique number). I generate a new random number and want to check if
this new number is already present in this array. One way is to check cell by
cell to see if the new random number is equal to that cell value. this works
fine but is slow. I have to repeat this step several thousands time and it is
making a big difference in computation time. Is there a way by which i can
check the entire array at once to see if a particular value is present?
for example see my code below:
********************************
RandomRowLowerBound = 1
RandomRowUpperBound = 50
NewRandomStartLine:
Randomize
RandomRowGenerated = Int((RandomRowUpperBound - RandomRowLowerBound + 1) *
Rnd + RandomRowLowerBound)
For CounterNumber13 = 1 To RandomRowUpperBound
If RandomRowAlreadyGeneratedArray(CounterNumber13, 1) = RandomRowGenerated
Then
GoTo NewRandomStartLine
End If
Next CounterNumber13
RandomRowAlreadyGeneratedArray(CounterNumber14, 1) = RandomRowGenerated
********************************
Here the program generates a random number in between 1 and 50. Then it goes
on to check if that number has already been generated in a previous step. The
program has record of random numbers already generated in
RandomRowAlreadyGeneratedArray which is updated after each successful new
random number found. To repeat my query again - Is there a way by which i can
check the entire array at once to see if a particular value is present?
TIA