I am working on a pokemon game and need a little insight to a dilemma i am having.
class pokemon
{
public:
void Generate_IV() //this function will generate a number between 1 and 31
{
srand(static_cast<unsigned int>(time))); //seed random number
int iv = (randomNumber %31) +1; ////get random number between 1 and 31
}
};
My dilemma is that all 600 something pokemon that need an iv generated for each stat (there are 6 stats per pokemon). how do i take the random number generated and make it to where each pokemon's stat will have a different iv on each pokemon? if i use a reference it will make iv equal to the stat and then it isn'r re-usable. any ideas?
In this example, random is a function that returns a random integer between its two parameters. You can easily write this function yourself by wrapping rand().
The variables hp_iv and so on are class members. This way, each pokemon will have its own copy of each variable, and each one will get a different random value.
Whatever you do, DO NOT seed the random number generate inside Generate_IV. This will cause some pokemon to receive the same IVs if time happens to be exactly the same during two calls to the function. Call srand once at the start of the program and don't call it again unless you have a good reason.
I will reinterpret this to see if i make sense so what i do is i make a function named random inside the generate iv function give the iv variables the parameters 1 and 31. where should i seed the rng? where i want the iv's to generate?
You don't necessarily need to make a function called random. Just use the rand() function and apply the % operator to get a number between 1 and 31.
You should seed the random number generator right at the beginning of main. After that, you don't have to seed it again, as it remembers how many numbers have been generated and uses that in its calculation, resulting in a new number each time.