Assign the colors in pairs. This way you're sure each card/square will have a matching card/square. You may want something like:
Code:
/**
*** TS = total squares
*** x = counter for total number of squares being used
*** y = counter for square color being placed
*** MC = max colors
*** color = current color
*** s = spot to place color
*** fs = free spot
*** uc = used count
**/
for( x = 0; x < TS; )
{
color = (rand()%MC)+1;
for(y=0;y<2;y++,x++)
{
/** Place 1 color. **/
s = rand()%(TS-x);
for( fs=0, uc=0; fs+uc < TS; )
{
if( squares[fs+uc] == 0 )
{ if( fs==s )
{ squares[fs+uc] = color; break; }
else
fs++;
}
else
uc++;
}
}
}
Ain't that puuuurrdy?
Quzah.