I have a 3x3 array of int's and I am working on an algorithm that will find the highest-valued element of the array and end up by assigning the relevant row and column to "rowChoice" and "colChoice", respectively. If there are two or more elements with the same value, I want my algorithm to choose randomly between them.

If I know the values are all different, I can just do something like this:

PHP Code:
// This is just a C code "fragment"...

// I'm assuming myArray[][] is an existing 3x3 array

int row=0col=0greatestSoFar=0rowChoice=0colChoice=0;

for(
row=0row<=2row++)
{
     for(
col=0col<=2col++)
     {
          if(
myArray[row][col]>greatestSoFar)
          {
               
greatestSoFar=myArray[row][col];
               
rowChoice=row;
               
colChoice=col;
          }
     }
}

// Program continues... 
Where I need help is the "choose randomly if two elements are the same" part. Any suggestions?

Thanks in advance for your help...

Andrew
(I'll be registering as soon as I get around to it... )