I believe the correct function name is rand();, not random();
Also, I would increment rows and columns by 1 when using the modulus operator - the first iteration you would be dividing by zero otherwise, which is not allowed.
Then what is it that isn't working?
Are you getting compiler errors - if so, which ones?
Is the output not what you expected, if so, what are you expecting and what is the output?
If you want to make sure the numbers are unique, you'll need to store them in an array and check every number generated to all the numbers in the array. If the number is in the array, generate a new random number and check again.
Here is something that will do what NwN is suggesting:
you'll need to include unordered_set
1 2 3 4 5 6
int rows = 5;
int columns = 5;
unordered_set<int> randNumbers;
while(randNumbers.size() < (rows*columns))
randNumbers.insert((rand()%100)+1);
This assumes user input is 5x5 matrix. So the code will fill a set with unique random numbers until it reaches the user defined matrix size.
This unordered_set size will be 25 so all what's left to do is iterate through and add the numbers from the unordered_set into the matrix as you loop through the rows and columns in your line 23.
unsigned array[rows*columns];
//fill the "matrix" 1 to rows*columns
for(unsigned K=0; K<rows; ++K)
for(unsigned L=0; L<columns; ++L)
array[K*columns+L] = K*columns+L+1;
//reorganize the data in a random way
std::random_shuffle(array, array+rows*columns);
If you insist in using a multidimensional array, cast the parameters