Hey all, So currently, I am trying to create a bool function, passing in two-dimensional array. I am trying to make it so that this function will generate a random row/ column position and then attempt to place an enum at that row-column position on the board. However, I am really stuck on what to do. I have my arrays and my random number generator, but I don't know how to go about combining them to place data inside random arrays without repeating them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// How do I generate a random position here and add data, then
//return (true or false) so that if it is false (There is already data in that position),
// randomize location again and try to place data on that position
//numberOfMines is user input so that it will only try to put data x amount of time
//(between 5-10)
bool checkMine(Symbols symbolArr[][COLS], int size, int numberOfMines);
{
srand(time(NULL));
}
I'm not even sure where to get started. Any help would be appreciated.
Here is my code, in the second function I assign the two variables RowNumber and ColumnNumber (Which are assigned random numbers each time the first function is called) to a string array's dimension parameters, I return this value to be dispayed in the main function. This outputs a different value stored in the two-dimensional each time these two functions are called again.
1 2 3 4 5 6 7 8 9
void Cards::setRandomNumbers() {
int randomNumber = rand(); // Generate random number between 0 and 65355
RowNumber = randomNumber % 4; // Get Array index (0-3) , divide //randomberNumber and get remainder
ColumnNumber = randomNumber % 13;// Array index(0 - 12), divide randomNumber and //get remainder
}