So you want to populate the board with random numbers in the range of [0, 18) and disallow more than two of a kind? I'd say use a frequency table for the range since it's small, and repeat getting the random number until you find one that doesn't go beyond the limit:
#include <cstdlib>
#include <iomanip>
#include <iostream>
int main()
{
using namespace std;
int board[6][6];
int freq[18] = {0};
for ( int i = 0; i < 6; i++ ) {
for ( int j = 0; j < 6; j++ ) {
int r;
do
r = rand() % 18;
while ( freq[r] >= 2 );
++freq[r];
board[i][j] = r;
}
}
for ( int i = 0; i < 6; i++ ) {
for ( int j = 0; j < 6; j++ )
cout<< left << setw ( 3 ) << board[i][j];
cout<<'\n';
}
}
The frequency table holds a count of all of the values in your range.
I'm here to prove you wrong.