I'm just starting to learn C++ and I can't figure out why the rand() is not working here for the rect0 object. When I run the program, it doesn't randomly draw rect0 as I thought it would. It just prints out at the same location every time. Here's the code:
class Rect
{
Vec2 min, max;
public:
Rect(int minx, int miny, int maxx, int maxy)
:min(minx, miny), max(maxx, maxy)
{}
Rect() {}
void draw(const char letter) const
{
for (int row = min.y; row < max.y; row++)
{
for (int col = min.x; col < max.x; col++)
{
if (row >= 0 && col >= 0)
{
moveCursor(col, row);
putchar(letter);
}
}
}
}
void setRandom(Rect & r)
{
r.min.x = rand() % 5;
r.max.x = rand() % 10 + 10;
r.min.y = rand() % 2;
r.max.y = rand() % 10 + 10;
}
int main()
{
Rect rect0;
rect0.setRandom(rect0);
rect0.draw('0');
moveCursor(0, 0); // re-print instructions
return 0;
}