I made a class with a function that returns a randomly generated pair<int, int>
to represent a coordinate pair. At the beginning of the function I have srand(time(NULL))
and I use rand() % 50
to get the random number pair.
It works great... as long as I only have one object of that. If I have two different objects of that class and call the function for each object (by this I mean trying to generate two different random coordinates for two different objects of this class), it returns the exact same coordinate pair for each object.
In retrospect, I can understand why this happens -- because I'm getting the random number based off of the current time, right? But what method should I use to return a random pair EVERY TIME I call that class's function?