Quote Originally Posted by VladimirF View Post
Well, this is what I said; it’s one way to do it. Not the best.
Are those x, y and z the same in both of your structures? You could extract that common data into its own struct, than knows how to randomize its data members:
Code:
int randgen(int upper)
{
	return rand() / (RAND_MAX / upper + 1);
}

struct CommonData
{
	int x;
	int y;
	int z;

	void randomize(int upper)
	{
		x = randgen(upper);
		y = randgen(upper);
		z = randgen(upper);
	}
};
Then you could have that struct as a part of your other classes:
Code:
struct Field
{
	CommonData cd;
};

struct House
{
	CommonData cd;
};
Then your main() might look like that:
Code:
int main()
{
	Field ball;
	House house;

	srand((unsigned)time( NULL )); 

	ball.cd.randomize(10);
	house.cd.randomize(10);
}
that is brilliant, thank you very much ^^