vendredi 15 mai 2015

How do I get a random seed for a random int range in C++11?

I have the following code to generate random ranges whenever I need:

random_device rd;
mt19937 eng(rd());

int get_random_int(int from, int to){
    uniform_int_distribution<int> dist(from, to);
    return dist(rd);
}

How do I feed the engine with a random seed like the current time or whatever? (I've tried to replace rd with time, but it's not possible). In my games, the enemies spawn in random positions in all directions and start moving towards you. It happens that, every time I start the game, they spawn in the same places (And that's exactly the opposite of what I want, since they're going to feel predictable).

Aucun commentaire:

Enregistrer un commentaire