+ 2
I'm having trouble generating a random number
I'm making a game in which the user is given a random number between 1 and 4, which depending on the number will roughly output the amount of damage you've done(eg. 1 would be small damage). this number would then be multiplied by 10 and subtracted from the enemy health. the problem is, when I run it, the enemy always takes 10 damage, meaning that i keep getting 1 each time. I have a strong feeling that the "stand((unsigned)time(0)) " function is the problem, but I'm not sure. https://code.sololearn.c
2 Respuestas
+ 2
`srand(time(nullptr))` gives a new seed for the rand() function.. So that can't be a problem.
Also.. Your link is not the link towards your playground.
0
avoid rand() for games, c++11 has better utilities for that http://en.cppreference.com/w/cpp/numeric/random look at this https://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful for more info