I'm looking for a way to generate two random numbers quickly in C++. The code is for a die and needs to generate a random number when rolled. My code currently looks like this:
Die::Die() {
srand(time(NULL));
}
void Die::roll() {
value = rand() % 6 + 1;
}
If I create two objects with this code, srand(), being a static (non-instance based) function, will generate a new seed for all objects. I've also tried doing this:
void Die::roll() {
srand(time(NULL));
value = rand() % 6 + 1;
}
Rather then having it in the constructor, but if I call them quickly like follows:
die0->roll();
die1->roll();
Their values are usually equal. Is there any way to actually make this random, every time? Thanks for all your help. :)